@auth/astro
@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
- Yarn
- pnpm
npm install @auth/core @auth/astro
yarn add @auth/core @auth/astro
pnpm add @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.