react-oauth2-code-pkce
Advanced tools
Comparing version 1.21.0 to 1.21.1
@@ -55,4 +55,7 @@ "use strict"; | ||
const [loginMethod, setLoginMethod] = (0, Hooks_1.default)(`${config.storageKeyPrefix}loginMethod`, 'redirect', config.storage); | ||
const [tokenData, setTokenData] = (0, react_1.useState)(); | ||
const [idTokenData, setIdTokenData] = (0, react_1.useState)(); | ||
const tokenData = (0, react_1.useMemo)(() => { | ||
if (config.decodeToken) | ||
return (0, decodeJWT_1.decodeAccessToken)(token); | ||
}, [token]); | ||
const idTokenData = (0, react_1.useMemo)(() => (0, decodeJWT_1.decodeIdToken)(idToken), [idToken]); | ||
const [error, setError] = (0, react_1.useState)(null); | ||
@@ -65,4 +68,2 @@ function clearStorage() { | ||
setIdToken(undefined); | ||
setTokenData(undefined); | ||
setIdTokenData(undefined); | ||
setLoginInProgress(false); | ||
@@ -191,19 +192,2 @@ } | ||
const didFetchTokens = (0, react_1.useRef)(false); | ||
// Load token-/idToken-data when tokens change | ||
(0, react_1.useEffect)(() => { | ||
try { | ||
if (idToken) | ||
setIdTokenData((0, decodeJWT_1.decodeJWT)(idToken)); | ||
} | ||
catch (e) { | ||
console.warn(`Failed to decode idToken: ${e.message}`); | ||
} | ||
try { | ||
if (token && config.decodeToken) | ||
setTokenData((0, decodeJWT_1.decodeJWT)(token)); | ||
} | ||
catch (e) { | ||
console.warn(`Failed to decode access token: ${e.message}`); | ||
} | ||
}, [token, idToken]); | ||
// Runs once on page load | ||
@@ -210,0 +194,0 @@ (0, react_1.useEffect)(() => { |
@@ -6,1 +6,3 @@ import type { TTokenData } from './types'; | ||
export declare const decodeJWT: (token: string) => TTokenData; | ||
export declare const decodeAccessToken: (token: string | null | undefined) => TTokenData | undefined; | ||
export declare const decodeIdToken: (idToken: string | null | undefined) => TTokenData | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decodeJWT = void 0; | ||
exports.decodeIdToken = exports.decodeAccessToken = exports.decodeJWT = void 0; | ||
/** | ||
@@ -24,1 +24,23 @@ * Decodes the base64 encoded JWT. Returns a TToken. | ||
exports.decodeJWT = decodeJWT; | ||
const decodeAccessToken = (token) => { | ||
if (!token || !token.length) | ||
return undefined; | ||
try { | ||
return (0, exports.decodeJWT)(token); | ||
} | ||
catch (e) { | ||
console.warn(`Failed to decode access token: ${e.message}`); | ||
} | ||
}; | ||
exports.decodeAccessToken = decodeAccessToken; | ||
const decodeIdToken = (idToken) => { | ||
if (!idToken || !idToken.length) | ||
return undefined; | ||
try { | ||
return (0, exports.decodeJWT)(idToken); | ||
} | ||
catch (e) { | ||
console.warn(`Failed to decode idToken: ${e.message}`); | ||
} | ||
}; | ||
exports.decodeIdToken = decodeIdToken; |
{ | ||
"name": "react-oauth2-code-pkce", | ||
"version": "1.21.0", | ||
"version": "1.21.1", | ||
"description": "Provider agnostic react package for OAuth2 Authorization Code flow with PKCE", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53170
809