The getAuth() function can be used to retrieve the current authentication state of the user from the server.

Returns

Returns an object containing the following fields:

session
KobbleServerAuthSession | null

The current session object, or null if the user is not authenticated.

KobbleServerAuthSession is defined as follows:

export type KobbleServerAuthSession = {
	user: User;
	accessToken: string;
	refreshToken: string;
	idToken: string;
}

User is defined as follows:

 export type User = {
	id: string;
	email: string;
	name: string | null;
	pictureUrl: string | null;
	isVerified: boolean;
	stripeId: string | null;
	updatedAt: Date;
	createdAt: Date;
};

Examples

import { getAuth } from '@kobbleio/next/server'

export default async function handler(req, res) {
  const { session } = await getAuth();

  if (!session) {
    return res.status(401).json({ error: 'Unauthorized' });
  }

  // An active session was found. User and tokens can be accessed from the session object.
  // <further logic here...>
}