tweaks
This commit is contained in:
parent
f91eb4bd73
commit
303e52da3e
@ -1,7 +1,10 @@
|
||||
import Cookies from 'cookies';
|
||||
import { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
|
||||
import { getUserInfo } from './api/remote';
|
||||
import { COOKIE_KEYS } from './constants';
|
||||
import { CurrentUserDto } from './types/user-response.interface';
|
||||
import { getActiveCookie } from './utils/get-active-cookie';
|
||||
|
||||
const inProd = process.env.NODE_ENV === 'production';
|
||||
|
||||
function withUser(
|
||||
handler: (
|
||||
@ -10,7 +13,13 @@ function withUser(
|
||||
) => Promise<GetServerSidePropsResult<any>>
|
||||
) {
|
||||
return async (ctx: GetServerSidePropsContext) => {
|
||||
const accessToken = getActiveCookie(ctx, 'authorization');
|
||||
const cookies = new Cookies(ctx.req, ctx.res, {
|
||||
secure: inProd,
|
||||
keys: COOKIE_KEYS,
|
||||
});
|
||||
|
||||
const accessToken = cookies.get('authorization', { signed: true });
|
||||
|
||||
let user: CurrentUserDto | undefined;
|
||||
if (accessToken) {
|
||||
try {
|
||||
|
@ -1,17 +0,0 @@
|
||||
import { GetServerSidePropsContext } from 'next';
|
||||
|
||||
import { getCookie } from './get-cookie';
|
||||
|
||||
export const getActiveCookie = (
|
||||
ctx: GetServerSidePropsContext,
|
||||
cookieName: string
|
||||
): string | undefined => {
|
||||
const setCookies = ctx.res.getHeader('set-cookie') as string[];
|
||||
const fallback = ctx.req.cookies[cookieName];
|
||||
const entry = setCookies?.find((item) => item.startsWith(cookieName));
|
||||
if (entry === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
return getCookie(cookieName, entry) || fallback;
|
||||
};
|
@ -23,6 +23,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
client_id: CLIENT_ID,
|
||||
response_type: 'code',
|
||||
redirect_uri: REDIRECT_URL,
|
||||
prompt: 'consent',
|
||||
scope: 'management',
|
||||
state,
|
||||
});
|
||||
|
Reference in New Issue
Block a user