mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-28 01:46:45 -05:00
fix: seralize session output (#448)
This commit is contained in:
@@ -2,7 +2,14 @@ import type { BetterAuthOptions } from "../types";
|
||||
import type { Adapter, Where } from "../types/adapter";
|
||||
import { getDate } from "../utils/date";
|
||||
import { getAuthTables } from "./get-tables";
|
||||
import type { Account, Session, User, Verification } from "./schema";
|
||||
import {
|
||||
parseSessionOutput,
|
||||
parseUserOutput,
|
||||
type Account,
|
||||
type Session,
|
||||
type User,
|
||||
type Verification,
|
||||
} from "./schema";
|
||||
import { generateId } from "../utils/id";
|
||||
import { getWithHooks } from "./with-hooks";
|
||||
import { getIp } from "../utils/get-request-ip";
|
||||
@@ -197,16 +204,18 @@ export const createInternalAdapter = (
|
||||
const sessionStringified = await secondaryStorage.get(sessionId);
|
||||
if (sessionStringified) {
|
||||
const s = JSON.parse(sessionStringified);
|
||||
const parsedSession = parseSessionOutput(ctx.options, {
|
||||
...s.session,
|
||||
expiresAt: new Date(s.session.expiresAt),
|
||||
});
|
||||
const parsedUser = parseUserOutput(ctx.options, {
|
||||
...s.user,
|
||||
createdAt: new Date(s.user.createdAt),
|
||||
updatedAt: new Date(s.user.updatedAt),
|
||||
});
|
||||
return {
|
||||
session: {
|
||||
...s.session,
|
||||
expiresAt: new Date(s.session.expiresAt),
|
||||
},
|
||||
user: {
|
||||
...s.user,
|
||||
createdAt: new Date(s.user.createdAt),
|
||||
updatedAt: new Date(s.user.updatedAt),
|
||||
},
|
||||
session: parsedSession,
|
||||
user: parsedUser,
|
||||
} as {
|
||||
session: Session;
|
||||
user: User;
|
||||
@@ -242,9 +251,13 @@ export const createInternalAdapter = (
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
const parsedUser = parseUserOutput(
|
||||
ctx.options,
|
||||
convertFromDB(tables.user.fields, user)!,
|
||||
);
|
||||
return {
|
||||
session,
|
||||
user: convertFromDB(tables.user.fields, user)!,
|
||||
session: parseSessionOutput(ctx.options, session),
|
||||
user: parsedUser,
|
||||
};
|
||||
},
|
||||
findSessions: async (sessionIds: string[]) => {
|
||||
|
||||
Reference in New Issue
Block a user