Drop-in UI authentication

When initializing the drop-in UI, you need to pass in a JWT with user claims for the signed in user. See Configuring authentication for more information about how to create the JWT.

Passing the JWT to Weavy

The recommended way to configure the JWT is by passing in a function that Weavy can call whenever a JWT is needed. The function should return the JWT as a string or return a promise that resolves the JWT as shown in the example below.


import Weavy from "@weavy/dropin-js";

const getToken = () => {
   return new Promise(function (resolve, reject) {
       // typically an api call to your backend which returns a JWT
       var token = getTokenFromSomewhere();
       if (token) {
           resolve(token);
       } else {
           reject("Failed to retrieve token");
       }
   });
}

const weavy = new Weavy({
 url: "https://weavy.example.com",
 jwt: getToken
});

It is also possible to configure the JWT directly as a string, but depending on the lifetime (exp claim) of your JWT there is a possibility that the token will expire during the page life-cycle in which case your user will be signed-out from Weavy.


import Weavy from "@weavy/dropin-js";

const weavy = new Weavy({
  url: "https://weavy.example.com",
  jwt: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
});

Signing out a user

If needed, you can explicitly sign out a user by calling the signOut() function. The function returns a Promise, so you can wait for the process to complete before doing other things.

const weavy = new Weavy();
weavy.authentication.signOut().then(function () {
    console.log("The user was signed out from Weavy");
});

Weavy Docs