Skip to content

Commit

Permalink
fix: PR review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRivers committed Oct 22, 2024
1 parent 544f3d7 commit 7d5ab3e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/session/getAccessTokenRaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ import {sessionManager} from './sessionManager';
*/
// @ts-ignore
export const getAccessTokenRawFactory = (req, res) => async () => {
return await sessionManager(req, res).getSessionItem('access_token');
return await (await sessionManager(req, res)).getSessionItem('access_token');
};
6 changes: 4 additions & 2 deletions src/session/getUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export const getUserFactory =
(req: NextApiRequest, res: NextApiResponse) =>
async <T = Record<string, any>>(): Promise<KindeUser<T>> => {
try {
const session = await sessionManager(req, res);

const idToken = jwtDecoder<KindeIdToken>(
(await (await sessionManager(req, res)).getSessionItem('id_token')) as string
(await session.getSessionItem('id_token')) as string
);

const accessToken = jwtDecoder<KindeAccessToken>(
(await (await sessionManager(req, res)).getSessionItem(
(await session.getSessionItem(
'access_token'
)) as string
);
Expand Down
14 changes: 10 additions & 4 deletions src/session/sessionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ const COOKIE_LIST = [
* @returns {Promise<import('@kinde-oss/kinde-typescript-sdk').SessionManager>}
*/
export const sessionManager = async (req, res) => {
if (!req) return appRouterSessionManager(await cookies());
return isAppRouter(req)
? appRouterSessionManager(await cookies())
: pageRouterSessionManager(req, res);
try{
const cookieStore = await cookies();
if (!req) return appRouterSessionManager(cookieStore);
return isAppRouter(req)
? appRouterSessionManager(cookieStore)
: pageRouterSessionManager(req, res);
} catch (error) {
console.error('Failed to initialize session manager:', error);
throw error;
}
};

/**
Expand Down
15 changes: 6 additions & 9 deletions src/utils/appRouter/setVerifierCookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import {cookies} from 'next/headers';
import {GLOBAL_COOKIE_OPTIONS} from '../../session/sessionManager';

export const setVerifierCookie = async (state, code_verifier, options) => {
const set = async () => {
(await cookies()).set({
name: `${config.SESSION_PREFIX}-${state}`,
value: JSON.stringify({code_verifier, options}),
maxAge: 60 * 15,
...GLOBAL_COOKIE_OPTIONS
});
}
await set();
(await cookies()).set({
name: `${config.SESSION_PREFIX}-${state}`,
value: JSON.stringify({code_verifier, options}),
maxAge: 60 * 15,
...GLOBAL_COOKIE_OPTIONS
});
};

0 comments on commit 7d5ab3e

Please sign in to comment.