I have a single page app using the Descope WebJS S...
# ask-a-descoper
c
I have a single page app using the Descope WebJS SDK. All works just fine for a simple login scenario with this cribbed from the sample apps:
Copy code
function launchDescope(flowId){
        const sdk = Descope({ projectId: projectId, autoRefresh: true });
        const wcElement = document.getElementsByTagName('descope-wc')[0];
        const onSuccess = (e) => {
           // [... send tokens to backend, etc ...]
        };
        const onError = (err) => console.log("#### Descope error", err);

        wcElement.addEventListener('success', onSuccess);
        wcElement.addEventListener('error', onError);
      }
Is there a way to detect if the user is already logged in so that I can render a full page overlay when the flow shows? The docs suggest:
Copy code
const descopeSdk = descopeSdk({projectId: '__ProjectID__'});
const sessionToken = descopeSdk.getSessionToken();

if(isJwtExpired(sessionToken)) {
  console.log('Session token has expired.');
} else {
  console.log('Session token is valid.');
}
but getSessionToken() was removed from the WebJS SDK a while ago. Is there an official approach for this? Looking at the SDK, nothing leaps out as a way to get this info
g
when you create the sdk, make sure to pass the
persistTokens
option (see in pacakge readme)
Copy code
const descopeSdk = descopeSdk({projectId: '__ProjectID__', persistTokens: true });
let me know if that works! We will make sure to update the docs accordingly
c
ah, that's surprising. I would expect an API function to always exist, but throw an exception on invalid preconditions
g
gotcha, this is an option the sdk, because not all users would want to persist the token but we will consider to make the default behavior so it will persist token, or change the beahvior to throw instead not defining the function at all, thanks!
c
thanks for the pointer. much appreciated
👍 1