@vyro-x/react-auth
Advanced tools
Comparing version 1.5.6 to 1.5.7
@@ -40,3 +40,3 @@ "use strict"; | ||
console.warn('failed to refresh auth session', err); | ||
if (err === refresh_1.RefreshErrorCodes.Expired || err === refresh_1.RefreshErrorCodes.Revoked) { | ||
if (err === refresh_1.SessionErrorCode.Expired || err === refresh_1.SessionErrorCode.Revoked) { | ||
(0, service_1.logout)({ | ||
@@ -43,0 +43,0 @@ post_logout_callback_url: window.location.href, |
@@ -1,5 +0,6 @@ | ||
export declare enum RefreshErrorCodes { | ||
export declare enum SessionErrorCode { | ||
Revoked = "session-revoked", | ||
Expired = "token-expired" | ||
Expired = "token-expired", | ||
NotVerfied = "not-verified" | ||
} | ||
export declare const refresh: () => Promise<void>; |
@@ -6,11 +6,12 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.refresh = exports.RefreshErrorCodes = void 0; | ||
exports.refresh = exports.SessionErrorCode = void 0; | ||
const axios_1 = __importDefault(require("axios")); | ||
const config_1 = require("./config"); | ||
const tokens_1 = require("./tokens"); | ||
var RefreshErrorCodes; | ||
(function (RefreshErrorCodes) { | ||
RefreshErrorCodes["Revoked"] = "session-revoked"; | ||
RefreshErrorCodes["Expired"] = "token-expired"; | ||
})(RefreshErrorCodes = exports.RefreshErrorCodes || (exports.RefreshErrorCodes = {})); | ||
var SessionErrorCode; | ||
(function (SessionErrorCode) { | ||
SessionErrorCode["Revoked"] = "session-revoked"; | ||
SessionErrorCode["Expired"] = "token-expired"; | ||
SessionErrorCode["NotVerfied"] = "not-verified"; | ||
})(SessionErrorCode = exports.SessionErrorCode || (exports.SessionErrorCode = {})); | ||
const refresh = async () => { | ||
@@ -20,3 +21,3 @@ const config = (0, config_1.getConfig)(); | ||
if (!refreshToken) { | ||
throw new Error(RefreshErrorCodes.Expired); | ||
throw new Error(SessionErrorCode.Expired); | ||
} | ||
@@ -37,6 +38,10 @@ try { | ||
console.warn('failed to refresh auth session', err); | ||
if (err?.response?.data?.code === RefreshErrorCodes.Revoked || | ||
err?.response?.data?.code === RefreshErrorCodes.Expired) { | ||
if (err?.response?.data?.code === SessionErrorCode.Revoked || | ||
err?.response?.data?.code === SessionErrorCode.Expired) { | ||
throw new Error(err.response.data.code); | ||
} | ||
if (err?.response?.data?.code === SessionErrorCode.NotVerfied) { | ||
// Fail silently if a session has not yet been verified | ||
return; | ||
} | ||
throw err; | ||
@@ -43,0 +48,0 @@ } |
{ | ||
"name": "@vyro-x/react-auth", | ||
"description": "Client authentication", | ||
"version": "1.5.6", | ||
"version": "1.5.7", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
34291
728