fix: properly merge updated data in account cookie (#6758)

This commit is contained in:
Joél Solano
2025-12-15 23:38:58 +01:00
committed by github-actions[bot]
parent 172ab54109
commit 5cec48dbd7
2 changed files with 22 additions and 17 deletions

View File

@@ -566,22 +566,24 @@ export const getAccessToken = createAuthEndpoint(
ctx.context,
);
newTokens = await provider.refreshAccessToken(refreshToken);
const updatedAccount = await ctx.context.internalAdapter.updateAccount(
account.id,
{
accessToken: await setTokenUtil(newTokens.accessToken, ctx.context),
accessTokenExpiresAt: newTokens.accessTokenExpiresAt,
refreshToken: await setTokenUtil(
newTokens.refreshToken,
ctx.context,
),
refreshTokenExpiresAt: newTokens.refreshTokenExpiresAt,
},
);
const storeAccountCookie =
ctx.context.options.account?.storeAccountCookie;
if (storeAccountCookie && updatedAccount) {
await setAccountCookie(ctx, updatedAccount);
const updatedData = {
accessToken: await setTokenUtil(newTokens.accessToken, ctx.context),
accessTokenExpiresAt: newTokens.accessTokenExpiresAt,
refreshToken: await setTokenUtil(newTokens.refreshToken, ctx.context),
refreshTokenExpiresAt: newTokens.refreshTokenExpiresAt,
};
let updatedAccount: Record<string, any> | null = null;
if (account.id) {
updatedAccount = await ctx.context.internalAdapter.updateAccount(
account.id,
updatedData,
);
}
if (ctx.context.options.account?.storeAccountCookie) {
await setAccountCookie(ctx, {
...account,
...(updatedAccount ?? updatedData),
});
}
}
const tokens = {

View File

@@ -104,7 +104,10 @@ export async function handleOAuthUserInfo(
}).filter(([_, value]) => value !== undefined),
);
if (c.context.options.account?.storeAccountCookie) {
await setAccountCookie(c, updateData);
await setAccountCookie(c, {
...account,
...updateData,
});
}
if (Object.keys(updateData).length > 0) {