Skip to content

Commit

Permalink
Fix token error handling in authOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
walnuts1018 committed Nov 7, 2023
1 parent 6e9bf3a commit fce9b19
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions front/src/app/api/auth/[...nextauth]/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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;
Expand Down

0 comments on commit fce9b19

Please sign in to comment.