> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kobble.io/llms.txt
> Use this file to discover all available pages before exploring further.

# getAuth()

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:

<ResponseField name="session" type="KobbleServerAuthSession | null">
  The current session object, or `null` if the user is not authenticated.

  `KobbleServerAuthSession` is defined as follows:

  ```ts theme={null}
  export type KobbleServerAuthSession = {
  	user: User;
  	accessToken: string;
  	refreshToken: string;
  	idToken: string;
  }
  ```

  `User` is defined as follows:

  ```ts theme={null}
   export type User = {
  	id: string;
  	email: string;
  	name: string | null;
  	pictureUrl: string | null;
  	isVerified: boolean;
  	stripeId: string | null;
  	updatedAt: Date;
  	createdAt: Date;
  };
  ```
</ResponseField>

### Examples

```ts theme={null}
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...>
}
```
