Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async startDisposableSession(privateIdentity: { identity: string }) {
const { identity } = privateIdentity;
const status = await this.tanker.start(identity);
switch (status) {
case Tanker.statuses.IDENTITY_REGISTRATION_NEEDED: {
const genVerificationKey = await this.tanker.generateVerificationKey();
await this.tanker.registerIdentity({ verificationKey: genVerificationKey });
return;
}
case Tanker.statuses.IDENTITY_VERIFICATION_NEEDED: {
throw new errors.InvalidArgument('This identity has already been used, create a new one.');
}
// When hitting back or forward on the browser you can start a disposable
// session with the same identity twice because the browser is caching
// the xhr request to fake-auth (or another identity server)
case Tanker.statuses.READY: {
return;
}
default:
throw new errors.InternalError(`Assertion error: unexpected status ${status}`);
}
}