Quick start
1
Install @kobbleio/javascript
Our SDK for javascript applications helps you to easily authenticate your users in your Vue.js application and manage their session.
2
Initialize the SDK
Create a file
src/kobble/index.ts
where you will initialize the SDK and export the Kobble instance.KOBBLE_DOMAIN and KOBBLE_CLIENT_ID can be found in your Kobble Application. The REDIRECT_URI must match the callback route we’re going to configure in the next step of this tutorial.
3
Create a callback handler
Once the user is logged in or signed up, Kobble will redirect the user back to your application with the user’s session information. You need to create a callback handler to handle this redirect.In this example we demonstrate how to do it in Vue.js but you can adapt it to any other javascript page.Use the Kobble client to handle the callback and redirect the user to the home page.
4
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 in vue.js:Authentication
The kobble client exposes various methods to manipulate the user authentication state.Login with redirect
This method triggers a redirect to your Kobble customer portal to start the authentication flow. Once the user is authenticated, Kobble will redirect the user back to your Callback URL configured while initializing the SDK.Logout
Delete the user session and redirect the user to the Kobble logout page. This method does redirect the user anywhere, you need to handle the redirection yourself if needed. ReturnsPromise<void>
Handle redirect callback
Promise<void>
Get user
Promise<User | null>
Where User is matching the following type:
Get access token
Promise<string | null>
Get id token
Promise<string | null>
Is authenticated
Allows you to check if the user is authenticated.Promise<boolean>
Listen to user state changes
The javascript SDK will keep track of the user state. However, you can also listen to the user state changes to trigger some custom logic in your application.The callback may be called multiple times. For example when you refresh the page, the callback will be called with user = null and then with the user object if present.
Permissions
List all permissions
Returns the list of permissions applied to the authenticated user.Promise<Permission[]>
Where Permission is matching the following type:
Check if the user has a permission
Promise<boolean>
Quotas
List all quotas
Returns the list of quotas applied to the authenticated user.Promise<Quota[]>
Where Quota is matching the following type:
Has remaining quota
You can check how much credit is left for a specific quota of the authenticated user by using thehasRemainingQuota
method.
Promise<boolean>
Integrations
Supabase
If you are using Supabase, you can easily integrate Kobble with your Supabase application and then generate a Supabase token for the authenticated user.Learn more about our Supabase integration in our Supabase guide
Promise<string | null>
Utils
Open profile page
Open your customer portal profile page in a new tab or the same tab depending on the target parameter.- target (optional):
'_blank' | '_self'
- default is'_self'
Promise<void>
Open portal pricing page
Open your customer portal pricing page in a new tab or the same tab depending on the target parameter.- target (optional):
'_blank' | '_self'
- default is'_self'
Promise<void>
Get portal URL
Get the URL of your customer portal page.string
Get portal profile URL
Get the URL of your customer portal profile page.string
Get portal pricing URL
Get the URL of your customer portal pricing page.string
Using it in a Chrome Extension
It’s possible to use this SDK in a chrome extension, however you will have some prerequisites to make it work.Setup
Instead of importing theKobbleClient
from @kobbleio/javascript
, you will need to import the KobbleWebExtensionClient
from @kobbleio/javascript/web-extension
.
Due to how chrome extensions work, you won’t need to pass the redirectUri parameter.
Update your manifest
You must add the following permissions in your Manifest.json file.Add the redirect URI
You must add the redirect URI of your Chrome Extension to your application in your Kobble dashboard.- Open the Applications tab of your Kobble dashboard.
- Click on the application you’re using in your Chrome extension.
- Scroll to the
Authorized redirect URIs
section and click onEdit
. - Add the following URI:
https://ID.chromiumapp.org/callback
whereID
is the ID of your Chrome extension.
The ID of your extension can be found on this page
chrome://extensions/
. Here is more information about how to find your ID. Note that the ID may change if you remove and reload your extension.Usage differences
Both SDKs are quite similar, however, theKobbleWebExtensionClient
does not need to handle the redirect callback.
Which means that the loginWithRedirect
method will directly return the user tokens and you won’t have to create a callback page nor using the handleRedirectCallback
method.