feat(chat): refresh agent credentials during tool calls

This commit is contained in:
2026-08-06 10:16:50 +08:00
parent b4c96f8524
commit 5037089057
10 changed files with 590 additions and 3 deletions
+8 -1
View File
@@ -80,7 +80,7 @@ const authOptions: NextAuthOptions = {
],
secret: process.env.NEXTAUTH_SECRET,
callbacks: {
jwt: async ({ token, profile, account }) => {
jwt: async ({ token, profile, account, trigger, session }) => {
if (profile?.sub) {
token.sub = profile.sub;
}
@@ -117,6 +117,13 @@ const authOptions: NextAuthOptions = {
return { ...token, error: "SessionExpired" };
}
if (
trigger === "update" &&
(session as { forceRefresh?: unknown } | undefined)?.forceRefresh === true
) {
return refreshAccessToken(token);
}
const accessTokenIsFresh =
typeof token.accessTokenExpires === "number" &&
typeof token.accessTokenIssuedAt === "number" &&