Skip to main content

@auth/astro

warning

@auth/astro is currently experimental. The API will change in the future.

@auth/astro is the official Astro integration for Auth.js. It provides a simple way to add authentication to your Astro app in a few lines of code.

Installation​

npm install @auth/core @auth/astro

AstroAuth()​

AstroAuth(options): object

Creates a set of Astro endpoints for authentication.

Parameters​

β–ͺ options: FullAuthConfig= authConfig

Returns​

object

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

GET()​

Parameters​

β–ͺ context: APIContext< Record< string, any >, Record< string, string > >

Returns​

Promise< ResponseInternal< any > >

POST()​

Parameters​

β–ͺ context: APIContext< Record< string, any >, Record< string, string > >

Returns​

Promise< ResponseInternal< any > >

Example​

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

getSession()​

getSession(req, options): Promise< Session | null >

Fetches the current session.

Parameters​

β–ͺ req: Request

The request object.

β–ͺ options: FullAuthConfig= authConfig

Returns​

Promise< Session | null >

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