This is an example demonstrating Logto integration with Astro.
Since Logto doesn't have an SDK for Astro, this example will be using Lucia Auth as the middleman between Astro and Logto.
- Login
- Sign Up
- Logout
- Protected Routes
- Database (Drizzle ORM & Postgres)
Install the dependencies.
pnpm install
Create a .env
file in the root of the project by copying the .env.example
file.
cp .env.example .env
Open the .env
file and update the DATABASE_URL
environment variable with your database's connection string.
# Database
DATABASE_URL=postgresql://user:password@host:port/database
...
Migrate your database.
pnpm drizzle-kit push
Now if you check your database, you should see the user
and session
tables.
Run the following command in your terminal to start the development server.
pnpm dev
Open http://localhost:4321 in your browser to see your app.
Now, follow the instructions in the Logto Authentication Setup section of these docs to get Logto set up. No need to follow the other sections, because those aren't relevant to this example.
This Astro + Logto auth example is licensed under the MIT License - see the LICENSE.md file for details.
If you're looking for something that already includes this auth setup, along with payments, blog, analytics, and other features all ready to go, check out RyzeKit, a fully-featured Astro SaaS boilerplate/starter kit.