mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-28 09:56:25 -05:00
fix(multi-session): return only unique user sessions
This commit is contained in:
@@ -66,7 +66,16 @@ export const multiSession = (options?: MultiSessionConfig) => {
|
||||
const validSessions = sessions.filter(
|
||||
(session) => session && session.session.expiresAt > new Date(),
|
||||
);
|
||||
return ctx.json(validSessions);
|
||||
const uniqueUserSessions = validSessions.reduce(
|
||||
(acc, session) => {
|
||||
if (!acc.find((s) => s.user.id === session.user.id)) {
|
||||
acc.push(session);
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
[] as typeof validSessions,
|
||||
);
|
||||
return ctx.json(uniqueUserSessions);
|
||||
},
|
||||
),
|
||||
setActiveSession: createAuthEndpoint(
|
||||
|
||||
Reference in New Issue
Block a user