npm create astro@latest -- --template TheOtterlord/starlight-auth
You can customize the available sign-in methods in auth.config.js
. Auth.js supports e-mail signin, traditional username/password auth, and 80+ OAuth providers. This template uses GitHub OAuth as an example.
By default, any authenticated user will be authorized to view your gated content. You can add additional authorization checks to the isAuthed
function in src/lib/auth.ts
. If the function returns true
, a user it authorized to access the page, and vice-versa if false
is returned. The example logic restricts access to routes defined in paths
above the isAuthed
function.
You may require different environment variables depending on your authentication method(s). Follow the example given in .env.example
to create your .env
file, replacing the GITHUB
variables with the variables for your auth provider.
In astro.config.ts
, comment out the adapter
for the platform you want to deploy to, removing the others. Deploy to your preferred provider, adding the environment variables you've defined.
Check out Starlight’s docs, read the Astro documentation, or jump into the Astro Discord server.