Vue.js quickstart
Add authentication to your Vue.js application in under 10 minutes using Kobble SDK.
You will learn how to:
- Create a new Vue.js application using Vite
- Configure
@kobbleio/javascript
SDK - Protect your application routes
Example repository
This is a simple Vue.js starter project that demonstrates how to implement authentication in a Vue.js application.
It uses vue-router, pinia, tailwind and @kobbleio/javascript SDK to manage the authentication state of the application.
Check our the repository for more information:
Getting started
Create your vue.js application
Scaffold your new Vue.js application using Vite.
Install @kobbleio/javascript
Our auth SDK for SPAs helps you to easily authenticate your users in your Vue.js application and manage their session.
Initialize the SDK
Create a file src/kobble/index.ts
where you will initialize the SDK and export the Kobble instance.
Setup the environment variables
Create a .env
file at the root of your project and add the following environment variables.
Create a callback handler
Install and configure vue-router.
Then create a new page view to handle our callback src/views/CallbackView.vue
.
Use the Kobble client to handle the callback and redirect the user to the home page on page mount.
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:
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:
🎉 You made it!
You have successfully added authentication to your Vue.js application using Kobble SDK.