From fce9b19a645b0e6bbc6eb5ff46304cac1384d58c Mon Sep 17 00:00:00 2001 From: walnuts1018 Date: Tue, 7 Nov 2023 23:45:57 +0900 Subject: [PATCH] Fix token error handling in authOptions --- front/src/app/api/auth/[...nextauth]/options.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/front/src/app/api/auth/[...nextauth]/options.ts b/front/src/app/api/auth/[...nextauth]/options.ts index 9ba319e..9dd3463 100644 --- a/front/src/app/api/auth/[...nextauth]/options.ts +++ b/front/src/app/api/auth/[...nextauth]/options.ts @@ -85,6 +85,7 @@ export const authOptions: NextAuthOptions = { iv: iv.toString('hex'), }) await redis.set("openchokin-" + token.sub as string, newCachedData, "EX", 60 * 60 * 24 * 30); + token.error = undefined; } catch (e) { console.error("Error refreshing token", e); return { ...token, error: "RefreshAccessTokenError" as const } @@ -97,6 +98,9 @@ export const authOptions: NextAuthOptions = { }, session: ({ session, token }: { token: JWT; session?: any }) => { session.error = token.error; + if (token.error === "RefreshAccessTokenError") { + throw new Error("RefreshAccessTokenError"); + } session.user.role = token.role; session.user.idToken = token.idToken; session.user.sub = token.sub;