Astro & Passkeys: Enhance your Astro apps with passkeys. Follow this tutorial to seamlessly integrate Corbado's web-JS for secure logins.
Amal
Created: August 1, 2024
Updated: October 9, 2024
We aim to make the Internet a safer place using passkeys. That's why we want to support developers with tutorials on how to implement passkeys.
5.1 Set Up your Corbado Account and Project
5.2 Embed the UI Component in the Frontend
In this blog post, we'll guide you through building an Astro application with passkey login functionality using the Corbado web-js component. Astro is an all-in-one web framework designed to simplify website creation. It boasts the performance and Corbado simplifies the integration of secure passkey authentication into your web apps. We'll show you how to embed Corbado's UI components and set up a secure login system. If you want to see the complete code, check out our sample Astro passkey application repository on GitHub. Here's a preview of the final passkey login interface with Astro:
Recent Articles
⚙️
How to Implement Passkeys in SolidJS Apps
♟️
Singapore Banks and Passkeys: Replacing SMS OTP
📖
Do Passkeys Work in Incognito Mode?
📖
WebAuthn Signal API: Update & Delete Passkeys on Client-Side
⚙️
Next.js Login Page: How to Implement Auth in Next.js
🏢
myGov Passkeys: Passkeys for Australian Government Services
This tutorial assumes you have a basic understanding of Astro, HTML, CSS, and JavaScript. To get started, make sure you have Node.js and Npm installed on your machine. For this example, we'll be using the latest version of Astro (version 4.12.3). Let's start building our secure passkey login application!
Subscribe to our Passkeys Substack for the latest news, insights and strategies.
SubscribeLet's explore the structure of our repository (full Astro passkeys GitHub repository). This organized architecture will help us efficiently manage and scale our Astro application.
. ├── src │ ├── components │ │ └── PasskeyList.astro │ ├── layouts │ │ └── Layout.astro │ ├── pages │ │ ├── index.astro │ │ └── profile.astro ├── .env ├── package.json
Here's a brief explanation of the relevant files and directories:
src/components/PasskeyList.astro
: Component for displaying the list of passkeys.src/pages/index.astro
: Component for the sign-up/login screen.src/pages/profile.astro
: Component for the user profile information shown after successful authentication..env
: Environment variables for configuring the application.Become part of our Passkeys Community for updates and support.
JoinIn this section, we'll explain step-by-step how to set up the Astro project. Let's get started by initializing a new Astro project:
Next, install the necessary dependencies:
To start the development server and see the basic skeleton of your application, run:
Your application will start at http://localhost:4321
. You should now see the basic structure of your Astro application.
To integrate Corbado's UI components in your Astro application, you need to follow these steps.
Visit the Corbado developer panel to sign up and create your account. You'll experience the passkey sign-up in action here! In the project setup wizard, begin by selecting an appropriate name for your project. For the product selection, opt for "Corbado Complete". Subsequently, select "DEV environment" along with "Corbado session management" options. Afterwards, you'll get more foundational setup guidance. Next, choose "Web app" as an application type and VanillaJS as your frontend framework (as Astro supports JavaScript, we can use the VanillaJS UI components). In the application settings, define your Application URL and Relying Party ID as follows:
http://localhost:4321
localhost
Lastly, navigate to the Corbado project settings to find your project ID under Corbado API access. Then, store the project ID in your environment file.
Your environment file should look like this:You'll need this project ID later to embed the Corbado UI component in your Astro app.
To get started with embedding the Corbado UI component in your Astro frontend, follow these steps:
corbadoSetup.js
file contains the shared logic for initializing Corbado. This file ensures that you only need to write the initialization logic once and reuse it across different components.
Here’s the complete code of the corbadoSetup.js
file:Login
Component:
The index.astro
component will handle user authentication by embedding Corbado's UI component.
Here’s the complete code of the index.astro
component:The PasskeyList.astro
component will display a list of passkeys. This component will be integrated into the Profile
component.
Here’s the complete code of the PasskeyList.astro
component:
The profile.astro
component will fetch and display user information using Corbado's API. It will also provide a UI for managing passkeys and logging out.
Here’s the complete code of the profile.astro
component:
Now, when you start your development server with
and navigate to http://localhost:4321
, you should see the authentication UI.
Once logged in, you'll be redirected to the profile page displaying user details and passkey list feature.
In this tutorial, we've covered how to set up an Astro application with Corbado’s web-js component for passkey authentication. This includes initializing an Astro project, integrating Corbado for authentication, and creating a profile page with logout functionality. With these steps, you should have a functional passkey login system in your Astro application. Besides the passkey-first authentication, Corbado provides simple session management, that we used for a retrieval of basic user data. If you want to read more about how Corbado's session management please check the docs here.
Table of Contents
Enjoyed this read?
🤝 Join our Passkeys Community
Share passkeys implementation tips and get support to free the world from passwords.
🚀 Subscribe to Substack
Get the latest news, strategies, and insights about passkeys sent straight to your inbox.
We provide UI components, SDKs and guides to help you add passkeys to your app in <1 hour
Start for free