mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-18 11:32:15 -05:00
fix: multi-session listing removing cookies before they are initatied
This commit is contained in:
@@ -230,9 +230,13 @@ export const prismaAdapter =
|
||||
async delete(data) {
|
||||
const { model, where } = data;
|
||||
const whereClause = convertWhereClause(model, where);
|
||||
await db[getModelName(model)].delete({
|
||||
where: whereClause,
|
||||
});
|
||||
try {
|
||||
await db[getModelName(model)].delete({
|
||||
where: whereClause,
|
||||
});
|
||||
} catch (e) {
|
||||
// If the record doesn't exist, we don't want to throw an error
|
||||
}
|
||||
},
|
||||
async deleteMany(data) {
|
||||
const { model, where } = data;
|
||||
|
||||
@@ -54,25 +54,24 @@ export const multiSession = (options?: MultiSessionConfig) => {
|
||||
const sessions =
|
||||
await ctx.context.internalAdapter.findSessions(sessionIds);
|
||||
|
||||
const validSessions = sessions
|
||||
.filter(
|
||||
(session) => session && session.session.expiresAt > new Date(),
|
||||
)
|
||||
.filter(
|
||||
(session, index, self) =>
|
||||
index === self.findIndex((s) => s.user.id === session.user.id),
|
||||
);
|
||||
const validSessions = sessions.filter(
|
||||
(session) => session && session.session.expiresAt > new Date(),
|
||||
);
|
||||
|
||||
Object.entries(cookies)
|
||||
.filter(([key]) => isMultiSessionCookie(key))
|
||||
.forEach(([key, value]) => {
|
||||
if (!validSessions.some((s) => s.session.id === value)) {
|
||||
ctx.setCookie(key, "", {
|
||||
...ctx.context.authCookies.sessionToken.options,
|
||||
maxAge: 0,
|
||||
});
|
||||
}
|
||||
});
|
||||
for (const [key] of Object.entries(cookies).filter(([key]) =>
|
||||
isMultiSessionCookie(key),
|
||||
)) {
|
||||
const sessionId = await ctx.getSignedCookie(
|
||||
key,
|
||||
ctx.context.secret,
|
||||
);
|
||||
if (!validSessions.some((s) => s.session.id === sessionId)) {
|
||||
ctx.setCookie(key, "", {
|
||||
...ctx.context.authCookies.sessionToken.options,
|
||||
maxAge: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.json(validSessions);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user