text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  var tslib_1 = require("tslib");
  var types_1 = require("@magic-sdk/types");
  var base_module_1 = require("./base-module");
  var json_rpc_1 = require("../core/json-rpc");
  var sdk_environment_1 = require("../core/sdk-environment");
  var AuthModule = /** @class */ (function (_super) {
      tslib_1.__extends(AuthModule, _super);
      function AuthModule() {
          return _super !== null && _super.apply(this, arguments) || this;
      }
      /**
       * Initiate the "magic link" login flow for a user. If the flow is successful,
       * this method will return a Decentralized ID token (with a default lifespan
       * of 15 minutes).
       */
      AuthModule.prototype.loginWithMagicLink = function (configuration) {
          var email = configuration.email, _a = configuration.showUI, showUI = _a === void 0 ? true : _a, redirectURI = configuration.redirectURI;
          var requestPayload = json_rpc_1.createJsonRpcRequestPayload(this.sdk.testMode ? types_1.MagicPayloadMethod.LoginWithMagicLinkTestMode : types_1.MagicPayloadMethod.LoginWithMagicLink, [{ email: email, showUI: showUI, redirectURI: redirectURI }]);
          return this.request(requestPayload);
      };
      /**
       * Log a user in with a special one-time-use credential token. This is
       * currently used during magic link flows with a configured redirect to
       * hydrate the user session at the end of the flow. If the flow is successful,
       * this method will return a Decentralized ID token (with a default lifespan
       * of 15 minutes).
       *
       * If no argument is provided, a credential is automatically parsed from
       * `window.location.search`.
       */
      AuthModule.prototype.loginWithCredential = function (credentialOrQueryString) {
          var credentialResolved = credentialOrQueryString !== null && credentialOrQueryString !== void 0 ? credentialOrQueryString : '';
          if (!credentialOrQueryString && sdk_environment_1.SDKEnvironment.platform === 'web') {
              credentialResolved = window.location.search;
              // Remove the query from the redirect callback as a precaution.
              var urlWithoutQuery = window.location.origin + window.location.pathname;
              window.history.replaceState(null, '', urlWithoutQuery);
          }
          var requestPayload = json_rpc_1.createJsonRpcRequestPayload(this.sdk.testMode ? types_1.MagicPayloadMethod.LoginWithCredentialTestMode : types_1.MagicPayloadMethod.LoginWithCredential, [credentialResolved]);
          return this.request(requestPayload);
      };
      return AuthModule;
  }(base_module_1.BaseModule));
  exports.AuthModule = AuthModule;
  //# sourceMappingURL=auth.js.map