Skip to content
Migrating from NextAuth.js v4? Read our migration guide.

server

AstroAuth()

AstroAuth(config?): {
  GET: handler;
  POST: handler;
}

Creates a set of Astro endpoints for authentication.

Parameters

ParameterTypeDescription
config?AuthConfigThe configuration for authentication providers and other options. Providing this will override your auth config file.

Returns

{
  GET: handler;
  POST: handler;
}

An object with GET and POST methods that can be exported in an Astro endpoint.

GET()

GET: (ctx) => Promise<undefined | Response> = handler;
Parameters
ParameterType
ctxAPIContext<Record<string, any>, Record<string, undefined | string>>
Returns

Promise<undefined | Response>

POST()

POST: (ctx) => Promise<undefined | Response> = handler;
Parameters
ParameterType
ctxAPIContext<Record<string, any>, Record<string, undefined | string>>
Returns

Promise<undefined | Response>

Example

export const { GET, POST } = AstroAuth({
  providers: [
    GitHub({
      clientId: process.env.GITHUB_ID!,
      clientSecret: process.env.GITHUB_SECRET!,
    }),
  ],
  debug: false,
})

auth()

auth(ctx, config?): Promise<Session | null>

Fetches the current session.

Parameters

ParameterType
ctxAPIContext<Record<string, any>, Record<string, undefined | string>>
config?AuthConfig

Returns

Promise<Session | null>

The current session, or null if there is no session.

Auth.js © Balázs Orbán and Team - 2024