Using the login embed, you can use Servicebot as an authentication system. This guide will go over how to configure the login embed in order to serve this functionality.

For technical documentation explaining the available options, go here

Integrating your app with the login embed

After one of your users logs in using the login embed, a handleResponse  function will be called, passing various information about the user as follows

//response object
{
    seats, //the seats this user belongs to if using seat management
    instances, //the subscriptions this user owns
    user, //the user object
    token //a JSON Web Token authorized for this user
}

This response should be used to log the user into your own app. This is usually accomplished by making an API call to your app which will validate the token and create a session cookie for your user. 

Servicebot.Login({
    url : "https://my-servicebot.serviceshop.io",
    selector : document.getElementById('servicebot-login-embed'),
    handleResponse: async function(response){

        //this an API that will log user in using the response
        const sessionAPI = "https://my-app.com/api/auth/session"
        let appResponse = await fetch(sessionAPI, {
            method: "POST",
            headers: {
                Content-Type: "application/json"
            },
            body: JSON.stringify(response)
        });
 
        //redirect the user to the dashboard
        window.location = "/dashboard";
    },
})

The handleResponse  function will be called if:

  • A user logs in
  • A seat completes their registration
  • A user resubscribes to a cancelled instance

Did this answer your question?