How to use @tanker/client-browser - 10 common examples

To help you get started, we’ve selected a few @tanker/client-browser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TankerHQ / sdk-js / packages / functional-tests / src / __tests__ / client.spec.web.js View on Github external
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;
};
github TankerHQ / quickstart-examples / client / web / notepad / src / index.js View on Github external
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'),
);
github TankerHQ / quickstart-examples / client / web / api-observer / src / App.js View on Github external
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');
      }
    }
  }
github TankerHQ / sdk-js / packages / filekit / src / FileKit.js View on Github external
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}`);
    }
  }
github TankerHQ / sdk-js / packages / filekit / src / FileKit.js View on Github external
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}`);
    }
  }
github TankerHQ / sdk-js / packages / filekit / src / FileKit.js View on Github external
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}`);
    }
  }
github TankerHQ / quickstart-examples / client / web / api-observer / src / App.js View on Github external
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');
      }
    }
  }
github TankerHQ / quickstart-examples / client / web / notepad / src / Session.js View on Github external
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}`);
    }
  }
github TankerHQ / sdk-js / packages / verification-ui / example / index.js View on Github external
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);
});
github TankerHQ / sdk-js / packages / filekit / src / FileKit.js View on Github external
constructor(config: TankerOptions) {
    this.tanker = new Tanker(config);
    this.verificationUI = new VerificationUI(this.tanker);
  }