UNPKG

@salte-auth/redirect

Version:

A Salte Auth handler for authenticating via Redirect!

61 lines (50 loc) 1.3 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var salteAuth = require('@salte-auth/salte-auth'); class Redirect extends salteAuth.Handler { constructor(config) { super(config); this.config = salteAuth.Utils.Common.defaults(this.config, { timeout: 10000 }); } get name() { return 'redirect'; } get auto() { return true; } connected(_ref) { var { action } = _ref; if (!action) return; var origin = this.storage.get('origin'); if (!origin) return; this.storage.delete('origin'); if (action === 'login') { // Does it make sense to navigate on 'logout'? // NOTE: This order, matters since navigate modifies the location. var parsed = salteAuth.Utils.URL.parse(location); this.navigate(origin); return parsed; } } open(_ref2) { var { url, timeout = this.config.timeout } = _ref2; this.storage.set('origin', location.href); this.navigate(url); return new Promise((_resolve, reject) => { setTimeout(() => { reject(new salteAuth.SalteAuthError({ code: 'redirect_timeout', message: "Timed out while redirecting." })); }, timeout); }); } } exports.Redirect = Redirect;