export const requireAuthSession = async (request: Request) => {
const { getUser, refreshTokens, isAuthenticated } =
await getKindeSession(request);
const isAuth = await isAuthenticated(); // 1
const cookies = new Cookies(request.headers.get("Cookie"), { path: "/" }); // 2
const accessToken = cookies.get("access_token"); // 2
if (!isAuth || !accessToken) {
throw redirect(ROUTE.LOGIN);
}
try {
const ver = await jwtVerify(accessToken, JWKS);
console.log({ ver });
} catch (e) {
const headers = await refreshTokens();
if (request.method === "GET" && headers)
throw redirect(request.url, { headers });
}
return getUser();
};
export const requireAuthSession = async (request: Request) => {
const { getUser, refreshTokens, isAuthenticated } =
await getKindeSession(request);
const isAuth = await isAuthenticated(); // 1
const cookies = new Cookies(request.headers.get("Cookie"), { path: "/" }); // 2
const accessToken = cookies.get("access_token"); // 2
if (!isAuth || !accessToken) {
throw redirect(ROUTE.LOGIN);
}
try {
const ver = await jwtVerify(accessToken, JWKS);
console.log({ ver });
} catch (e) {
const headers = await refreshTokens();
if (request.method === "GET" && headers)
throw redirect(request.url, { headers });
}
return getUser();
};