How to use the @tanker/client-browser.errors.InvalidArgument function in @tanker/client-browser

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 / 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}`);
    }
  }