feat(chat): refresh agent credentials during tool calls
This commit is contained in:
@@ -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" &&
|
||||
|
||||
Reference in New Issue
Block a user