Vue.js & Passkeys: Elevate your Vue.js projects with secure passkey implementation by following this developer tutorial.
Vincent
Created: August 30, 2023
Updated: September 3, 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. Set Up the Corbado UI Components for Passkey Authentication
5.1 Set Up Your Corbado Account and Project
In this blog post, we'll be walking through the process of building a sample application with passkey authentication using Vue.js. We'll cover how to embed the Corbado web-js UI components and implement passkey login functionality for a seamless user experience.
If you want to see the finished code, please have a look at our sample Vue.js passkey application repository on GitHub.
The result looks as follows:
Corbado Auth Component
This tutorial assumes basic familiarity with Vue.js, HTML, CSS, and JavaScript. Let's dive in! Moreover, you need to have Node and NPM installed on your machine.
We're using the Composition API and Vue 3 in this example.
Let's first discuss the structure of our project (full Vue.js passkeys GitHub repo):
. ├── .env ├── package.json ├── vite.config.js └── src ├── router | └── login.component.ts ├── views | ├── HomeView.vue | └── ProfileView.vue ├── App.vue └── main.js
The rest of the files of this project can be ignored for the purpose of this tutorial.
Become part of our Passkeys Community for updates and support.
JoinIn the following, we explain step-by-step what needs to be done to successfully set up the Vue.js project.
Let's start out by initializing a new Vue.js project. In this tutorial, were using Vue.js version 3.3.4:
In the installation guide steps, we select the following:
Then run
Let's also install the Corbado web-js dependency:
If you run
the sample skeleton application starts at http://localhost:5173:
Visit the Corbado developer panel to sign up and create your account (you'll see 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, specify your technology stack and select "DEV" along with "Corbado session management" options. Afterwards, you'll get more foundational setup guidance.
Next, choose "Web app" as an application type and Vue.js as your framework. In the application settings, define your Application URL and Relying Party ID as follows:
localhost
Lastly, retrieve your project ID from the developer panel and store it in your environment file. You can find it here under Corbado API access.
Your environment file should look like this:
You'll need it later to embed the Corbado UI component in your Vue.js app.
Now, let's jump back to the code we created from step 4.
Delete the entire /src/components
folder to clean up the project and rename
the /src/views/AboutView.vue
file to /src/views/ProfileView.vue
, so it fits our
logic better.
Open the /src/router/index.js
file and change the /about
route to /profile
(change the name accordingly and don't forget to import the component):
In the App.vue
file, import the global Corbado object and use it to initialize the Corbado project.
We need to hand it our project ID from the .env
file and set the dark mode to "on".
After the initialization, we set isInitialized
to true to show our page:
Then, we use the global Corbado object to mount the authentication UI in the HomeView.vue
file.
We'll make it redirect the user to the /profile
page once he authenticates or if he's already signed in.
After successful authentication, the Corbado auth component redirects the user to the profile page. This page renders basic user information (user ID and name) and provides a button to logout. It makes use of the Corbado object to retrieve the user data and logs him out if needed.
Create a ProfileView.vue
file and add the following code:
If the user isn't logged in, we also provide him with the option to go back to the home page and log in.
If everything is set up and installed, run the application with
You should see the following screen:
Corbado Auth Component
After successful sign-up / login, you see the profile page:
Add passkeys to your Vue.js app.
Start For FreeThis tutorial showed how easy it is to add passwordless authentication with passkeys to a Vue.js app using Corbado. 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 you can leverage Corbado's session management to retrieve backend data, please check our documentation hereor if you want to add Corbado to your existing app with existing users, please see our documentation 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