Skip to content

Lucia

Introduction

This starter kit provides Lucia (v4, the latest version) as an option for authentication. Lucia is an open-source authentication library to implement auth from scratch. By using this starter kit, Lucia authentication has already been implemented for you. Now, you just need to get it set up and running.

Email & Password Setup

  1. Generate a 128 bit (16 byte) string and base64 encode it. You can do this by going to a new tab in your terminal and running the command below. This will use OpenSSL to generate an encryption key.
Terminal window
openssl rand --base64 16
  1. In the .env file of your Astro project, copy your encryption key into the ENCRYPTION_KEY environment variable. An example is shown below.
...
# Authentication
ENCRYPTION_KEY="L9pSomeRandomCharsvkHuC9=="
...

  1. Next, you will need to set up email functionality so that a confirmation email can be sent to new users after they register. Please follow the Email guide to get email configured. Return to here when you’re done.

  1. Now in the home page of your app, you can test email & password authentication by clicking the Sign Up button and creating a new account. Once you have created an account, the app should redirect you to the verify email page. After verifying your email, you should be redirected to the dashboard page. Signing out should redirect you to the login page.

Github Social Login Setup

  1. To get set up with Github for social login, follow the official instructions to create a Github OAuth app. For the Authorization callback URL, add /auth/login/github/callback after the home page URL, something like: http://localhost:4321/auth/login/github/callback
Github-OAuth-New-App
  1. Copy your Github Client ID and Client secret to your .env file.
...
GITHUB_CLIENT_ID=<your client id>
GITHUB_CLIENT_SECRET=<your client secret>
...
  1. Now in your Astro app, you can test Github social login by clicking the Sign Up button and selecting Login with Github. You should be redirected to Github to sign in, and then redirected back to the app. Signing out should redirect you to the login page.

Other Social Providers

Lucia uses Arctic to handle social logins. You can see a list of social providers and their set up instructions on their website.

Next Steps

🚀 Congratulations, you’ve successfully set up authentication! Proceed to the Payments page to continue with setup.