Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const makeTanker = (appId: b64string): Tanker => {
const tanker = new Tanker({
appId,
// $FlowIKnow adapter key is passed as a default option by @tanker/client-browser
dataStore: { prefix: makePrefix() },
sdkType: 'js-functional-tests-web',
url: tankerUrl,
});
return tanker;
};
import 'core-js/stable';
import 'regenerator-runtime/runtime';
import '@babel/register';
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { Tanker } from '@tanker/client-browser';
import Session from './Session';
import App from './components/App';
const session = new Session();
/* eslint-disable-next-line */
console.log(`Tanker version: ${Tanker.version}`);
ReactDOM.render(
,
document.getElementById('root'),
);
initTanker = async () => {
try {
const res = await doRequest(`${serverRoot}/config`);
const config = await res.json();
this.tanker = new Tanker(config);
this.log('initTanker', config.appId);
this.setState({ loading: false });
} catch (e) {
this.log(e);
// Could it be that the server is not started yet?
if (!(e instanceof errors.TankerError)) {
this.log('serverHint');
}
}
}
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}`);
}
}
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}`);
}
}
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}`);
}
}
initTanker = async () => {
try {
const res = await doRequest(`${serverRoot}/config`);
const config = await res.json();
this.tanker = new Tanker(config);
this.log('initTanker', config.appId);
this.setState({ loading: false });
} catch (e) {
this.log(e);
// Could it be that the server is not started yet?
if (!(e instanceof errors.TankerError)) {
this.log('serverHint');
}
}
}
async initTanker() {
if (!this.user) throw new Error('Assertion error: cannot start Tanker without a user');
const config = await this.serverApi.tankerConfig();
this.tanker = new Tanker(config);
const result = await this.tanker.start(this.user.identity);
if (result === READY) {
await this.triggerClaimIfNeeded();
} else if (result === IDENTITY_REGISTRATION_NEEDED) {
this.status = 'register';
} else if (result === IDENTITY_VERIFICATION_NEEDED) {
this.status = 'verify';
} else {
throw new Error(`Unexpected status ${result}`);
}
}
createIdentity(appId, appSecret, userId).then(async identity => {
const provisionalIdentity = await createProvisionalIdentity(appId, email);
const tanker = new Tanker({ appId, url });
const verificationUI = new VerificationUI(tanker);
await verificationUI.start(email, identity, provisionalIdentity);
});
constructor(config: TankerOptions) {
this.tanker = new Tanker(config);
this.verificationUI = new VerificationUI(this.tanker);
}