mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-31 19:36:46 -05:00
fix: properly merge updated data in account cookie (#6758)
This commit is contained in:
committed by
github-actions[bot]
parent
172ab54109
commit
5cec48dbd7
@@ -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 = {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user