Skip to content

Commit

Permalink
Merge pull request #156 from kinde-oss/peter/remove-user-cookie-depen…
Browse files Browse the repository at this point in the history
…dency

Peter/remove user cookie dependency
  • Loading branch information
peterphanouvong authored Apr 30, 2024
2 parents 6a515fb + 8e8f854 commit be4a4dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/authMiddleware/authMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const handleMiddleware = async (req, options, onSuccess) => {
}

const accessTokenValue = jwt_decode(req.cookies.get('access_token').value);
const idTokenValue = jwt_decode(req.cookies.get('id_token')?.value);

const isAuthorized = options?.isAuthorized
? options.isAuthorized({req, token: accessTokenValue})
Expand All @@ -69,7 +70,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,
picture: idTokenValue.picture
}
});
}

Expand Down
14 changes: 8 additions & 6 deletions src/session/sessionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
)
]);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/utils/removeTrailingSlash.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function removeTrailingSlash(url) {
if (url === undefined) return url;
if (url === undefined || url === null) return undefined;

url = url.trim();

Expand Down

0 comments on commit be4a4dc

Please sign in to comment.