From a64947dfbcdb3dc8c75f815c3dc05e24dece1b32 Mon Sep 17 00:00:00 2001 From: Peter Phanouvong Date: Tue, 30 Apr 2024 17:00:37 +1000 Subject: [PATCH 1/5] fix: null env values --- src/utils/removeTrailingSlash.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/removeTrailingSlash.js b/src/utils/removeTrailingSlash.js index 670a18c..a26e5fa 100644 --- a/src/utils/removeTrailingSlash.js +++ b/src/utils/removeTrailingSlash.js @@ -1,5 +1,5 @@ export function removeTrailingSlash(url) { - if (url === undefined) return url; + if (url === undefined || url === null) return undefined; url = url.trim(); From 005ed768a38b49fd9d2f3f2c790f0c325491e1d8 Mon Sep 17 00:00:00 2001 From: Peter Phanouvong Date: Tue, 30 Apr 2024 17:00:50 +1000 Subject: [PATCH 2/5] fix: remove user cookie dependency --- src/authMiddleware/authMiddleware.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/authMiddleware/authMiddleware.js b/src/authMiddleware/authMiddleware.js index af6d305..b4d7906 100644 --- a/src/authMiddleware/authMiddleware.js +++ b/src/authMiddleware/authMiddleware.js @@ -61,6 +61,9 @@ const handleMiddleware = async (req, options, onSuccess) => { } const accessTokenValue = jwt_decode(req.cookies.get('access_token').value); + const idTokenValue = JSON.parse( + jwt_decode(req.cookies.get('id_token')?.value) + ); const isAuthorized = options?.isAuthorized ? options.isAuthorized({req, token: accessTokenValue}) @@ -69,7 +72,13 @@ const handleMiddleware = async (req, options, onSuccess) => { if (isAuthorized && onSuccess) { return await onSuccess({ token: accessTokenValue, - user: JSON.parse(req.cookies.get('user').value) + user: { + family_name: idTokenValue.family_name, + given_name: idTokenValue.given_name, + email: idTokenValue.email, + id: idTokenValue.sub, + picutre: idTokenValue.picture + } }); } From 7da3a4a15d2efcd1dbf179019e24164c7d17466e Mon Sep 17 00:00:00 2001 From: Peter Phanouvong Date: Wed, 1 May 2024 09:17:47 +1000 Subject: [PATCH 3/5] chore: use latest TS version --- package.json | 2 +- src/session/sessionManager.js | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index a1dee2b..93630b3 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ }, "dependencies": { "@babel/preset-env": "^7.23.9", - "@kinde-oss/kinde-typescript-sdk": "^2.8.0", + "@kinde-oss/kinde-typescript-sdk": "2.9.0", "cookie": "^0.6.0", "crypto-js": "^4.1.1", "jwt-decode": "^3.1.2", diff --git a/src/session/sessionManager.js b/src/session/sessionManager.js index 3f23a26..fb496e6 100644 --- a/src/session/sessionManager.js +++ b/src/session/sessionManager.js @@ -175,12 +175,14 @@ export const pageRouterSessionManager = (req, res) => { ]); }, destroySession: () => { - res?.setHeader('Set-Cookie', [ ...COOKIE_LIST.map((name) => - cookie.serialize(name, '', { - domain: config.cookieDomain ? config.cookieDomain : undefined, - maxAge: -1, - ...GLOBAL_COOKIE_OPTIONS - })) + res?.setHeader('Set-Cookie', [ + ...COOKIE_LIST.map((name) => + cookie.serialize(name, '', { + domain: config.cookieDomain ? config.cookieDomain : undefined, + maxAge: -1, + ...GLOBAL_COOKIE_OPTIONS + }) + ) ]); } }; From ff662f010730b21c27e66ac0609cd8a86957044b Mon Sep 17 00:00:00 2001 From: Peter Phanouvong Date: Wed, 1 May 2024 09:40:03 +1000 Subject: [PATCH 4/5] fix: decoding id token --- src/authMiddleware/authMiddleware.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/authMiddleware/authMiddleware.js b/src/authMiddleware/authMiddleware.js index b4d7906..9cf8e6c 100644 --- a/src/authMiddleware/authMiddleware.js +++ b/src/authMiddleware/authMiddleware.js @@ -61,9 +61,7 @@ const handleMiddleware = async (req, options, onSuccess) => { } const accessTokenValue = jwt_decode(req.cookies.get('access_token').value); - const idTokenValue = JSON.parse( - jwt_decode(req.cookies.get('id_token')?.value) - ); + const idTokenValue = jwt_decode(req.cookies.get('id_token')?.value); const isAuthorized = options?.isAuthorized ? options.isAuthorized({req, token: accessTokenValue}) From 8e8f8540e5b50584a643205f9e0c34e1bdd39ed6 Mon Sep 17 00:00:00 2001 From: Peter Phanouvong Date: Wed, 1 May 2024 09:43:23 +1000 Subject: [PATCH 5/5] fix: typo --- src/authMiddleware/authMiddleware.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/authMiddleware/authMiddleware.js b/src/authMiddleware/authMiddleware.js index 9cf8e6c..7c141ef 100644 --- a/src/authMiddleware/authMiddleware.js +++ b/src/authMiddleware/authMiddleware.js @@ -75,7 +75,7 @@ const handleMiddleware = async (req, options, onSuccess) => { given_name: idTokenValue.given_name, email: idTokenValue.email, id: idTokenValue.sub, - picutre: idTokenValue.picture + picture: idTokenValue.picture } }); }