TheOtterlord / starlight-auth

Starlight + Auth.js template
https://starlight-auth-development.vercel.app/
41 stars 3 forks source link
astro authjs starlight

Starlight Starter Kit: Auth

Built with Starlight

npm create astro@latest -- --template TheOtterlord/starlight-auth

Open in StackBlitz Open with CodeSandbox Deploy with Vercel

Setting up Auth

Authentication

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.

Authorization

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.

Environment Variables

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.

Deploy

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.

Want to learn more?

Check out Starlight’s docs, read the Astro documentation, or jump into the Astro Discord server.