@descope/web-js-sdk
Descope JavaScript web SDK
Usage
Install the package
npm install @descope/web-js-sdk
Use it
import descopeSdk from '@descope/web-js-sdk';
const myProjectId = 'xxx';
const sdk = descopeSdk({
projectId: myProjectId,
persistTokens: true,
*/
sessionTokenViaCookie: false,
autoRefresh: true,
storeLastAuthenticatedUser: false,
keepLastAuthenticatedUserAfterLogout: true
});
sdk.onSessionTokenChange((newSession, oldSession) => {
});
sdk.onUserChange((newUser, oldUser) => {
});
sdk.refresh();
const userIdentifier = 'identifier';
let res = await sdk.otp.signIn.email(userIdentifier);
if (!res.ok) {
throw Error('Failed to sign in');
}
const codeFromEmail = '1234';
res = await sdk.otp.verify.email(userIdentifier, codeFromEmail);
if (!res.ok) {
throw Error('Failed to sign in');
}
const sessionToken = sdk.getSessionToken();
Run Example
To run the example:
- Install dependencies
pnpm i
- Run the sample
pnpm run start
The browser open a tab with directory tree of available examples. Click on the desire directory and follow the instruction.
NOTE: This package is a part of a monorepo. so if you make changes in a dependency, you will have to rerun npm run start
(this is a temporary solution until we improve the process to fit to monorepo).