You will learn how to:
- Create a new Vue.js application using Vite
- Configure
@kobbleio/javascript
SDK - Protect your application routes
Pre-requisites: You need to set up your Kobble account before starting this guide.
Example repository

Getting started
1
Create your vue.js application
Scaffold your new Vue.js application using Vite.
2
Install @kobbleio/javascript
Our auth SDK for SPAs helps you to easily authenticate your users in your Vue.js application and manage their session.
3
Initialize the SDK
Create a file
src/kobble/index.ts
where you will initialize the SDK and export the Kobble instance.4
Setup the environment variables
Create a
.env
file at the root of your project and add the following environment variables.KOBBLE_DOMAIN and KOBBLE_CLIENT_ID can be found in the Kobble Application we created earlier. The REDIRECT_URI must match the callback route weβre going to configure in the next step of this tutorial.
5
Create a callback handler
Install and configure vue-router.Then create a new page view to handle our callback
If youβre not familiar with Vue Router, you can check our router configuration here.
src/views/CallbackView.vue
.Use the Kobble client to handle the callback and redirect the user to the home page on page mount.6
Use the loginWithRedirect method
Then we can use the
loginWithRedirect
method to redirect the user to the Kobble login page whenever we want to authenticate the user.For example with a simple button:7
Going further
At this stage, you have successfully added authentication to your Vue.js application using Kobble SDK.Now you can use all methods provided by our SDK to protect your routes, get the user profile, listen to the user state changes and more.Here are some useful examples:You can also listen to the user state changes: