[RangeError: Too many properties to enumerate]

When i try to get session, via the /api/auth/get-session or via the getSessionCookie helper, i always got a 500 error with "[RangeError: Too many properties to enumerate]", without any others details. If you have some ideas to solve it, it would be a pleasure thx
1 Reply
boul2gom
boul2gomOP2mo ago
Here is my auth.ts :
const prisma = new PrismaClient();

export const cookie_prefix = "finary-auth";
export const cookie_name = "session_token";

export const auth_server = betterAuth({
appName: "Finary",

database: prismaAdapter(prisma, {
provider: "postgresql",
}),
secondaryStorage: secondary_storage,
rateLimit: {
enabled: true,
window: 10,
max: 100,
},

logger: {
disabled: false,
level: "debug",
log: (level: LogLevel, message: string, ...args: any[]) => {
console.log("[BetterAuth] " + level + " " + message, ...args);
},
},

emailAndPassword: {
enabled: true,
autoSignIn: true,
minPasswordLength: 12,
requireEmailVerification: true,

password: {
hash: (password: string) => argon2.hash(password),
verify: (data: { hash: string; password: string }) => {
return argon2.verify(data.hash, data.password);
},
},
sendResetPassword: async ({ user, url }) => {
const component = new_email(url, "Reset your password");

console.log(
"[Send reset password] Sending email to",
user.email,
"with url",
url,
);
await send_email(user.email, "Reset your password", component);
},
},
emailVerification: {
sendVerificationEmail: async ({ user, url }) => {
const component = new_email(url, "Verify your email address");

console.log(
"[Send verification email] Sending email to",
user.email,
"with url",
url,
);
await send_email(user.email, "Verify your email address", component);
},
},

socialProviders: {
github: {
clientId: environment.GITHUB_ID,
clientSecret: environment.GITHUB_SECRET,
},
google: {
clientId: environment.GOOGLE_ID,
clientSecret: environment.GOOGLE_SECRET,
},
},
account: {
accountLinking: {
allowDifferentEmails: true,
trustedProviders: ["google", "github"],
},
},
const prisma = new PrismaClient();

export const cookie_prefix = "finary-auth";
export const cookie_name = "session_token";

export const auth_server = betterAuth({
appName: "Finary",

database: prismaAdapter(prisma, {
provider: "postgresql",
}),
secondaryStorage: secondary_storage,
rateLimit: {
enabled: true,
window: 10,
max: 100,
},

logger: {
disabled: false,
level: "debug",
log: (level: LogLevel, message: string, ...args: any[]) => {
console.log("[BetterAuth] " + level + " " + message, ...args);
},
},

emailAndPassword: {
enabled: true,
autoSignIn: true,
minPasswordLength: 12,
requireEmailVerification: true,

password: {
hash: (password: string) => argon2.hash(password),
verify: (data: { hash: string; password: string }) => {
return argon2.verify(data.hash, data.password);
},
},
sendResetPassword: async ({ user, url }) => {
const component = new_email(url, "Reset your password");

console.log(
"[Send reset password] Sending email to",
user.email,
"with url",
url,
);
await send_email(user.email, "Reset your password", component);
},
},
emailVerification: {
sendVerificationEmail: async ({ user, url }) => {
const component = new_email(url, "Verify your email address");

console.log(
"[Send verification email] Sending email to",
user.email,
"with url",
url,
);
await send_email(user.email, "Verify your email address", component);
},
},

socialProviders: {
github: {
clientId: environment.GITHUB_ID,
clientSecret: environment.GITHUB_SECRET,
},
google: {
clientId: environment.GOOGLE_ID,
clientSecret: environment.GOOGLE_SECRET,
},
},
account: {
accountLinking: {
allowDifferentEmails: true,
trustedProviders: ["google", "github"],
},
},
plugins: [
twoFactor({
otpOptions: {
sendOTP: async ({ user, otp }) => {
const url = `${environment.NEXT_PUBLIC_APPLICATION_URL}/auth/verify-otp?token=${otp}`;
const component = new_email(url, "Verify your sign in");

await send_email(user.email, "Verify your sign in", component);
},
},
}),
passkey({
rpID: new URL(environment.NEXT_PUBLIC_APPLICATION_URL).hostname,
rpName: "Finary",
origin: environment.NEXT_PUBLIC_APPLICATION_URL,
authenticatorSelection: {
residentKey: "preferred",
userVerification: "preferred",
},
}),
oneTap({
clientId: environment.GOOGLE_ID,
}),

captcha({
provider: "cloudflare-turnstile",
secretKey: environment.TURNSTILE_SECRET_KEY,
endpoints: ["/account/sign-up", "/account/sign-in"],
}),

nextCookies() /** Must be the last plugin */,
],

advanced: {
cookieName: cookie_name,
cookiePrefix: cookie_prefix,
useSecureCookies: environment.RUNTIME_MODE === "production",

generateId: () => uuid_v4(),
},
});
plugins: [
twoFactor({
otpOptions: {
sendOTP: async ({ user, otp }) => {
const url = `${environment.NEXT_PUBLIC_APPLICATION_URL}/auth/verify-otp?token=${otp}`;
const component = new_email(url, "Verify your sign in");

await send_email(user.email, "Verify your sign in", component);
},
},
}),
passkey({
rpID: new URL(environment.NEXT_PUBLIC_APPLICATION_URL).hostname,
rpName: "Finary",
origin: environment.NEXT_PUBLIC_APPLICATION_URL,
authenticatorSelection: {
residentKey: "preferred",
userVerification: "preferred",
},
}),
oneTap({
clientId: environment.GOOGLE_ID,
}),

captcha({
provider: "cloudflare-turnstile",
secretKey: environment.TURNSTILE_SECRET_KEY,
endpoints: ["/account/sign-up", "/account/sign-in"],
}),

nextCookies() /** Must be the last plugin */,
],

advanced: {
cookieName: cookie_name,
cookiePrefix: cookie_prefix,
useSecureCookies: environment.RUNTIME_MODE === "production",

generateId: () => uuid_v4(),
},
});
Even when using fresh templates, i got this error Oh and this is my prisma schema, if needed :
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("POSTGRES_URL")
}

model User {
id String @id
name String
email String
emailVerified Boolean @map("email_verified")

image String?

sessions Session[]
accounts Account[]
passkeys Passkey[]

twofactors TwoFactor[]
twoFactorEnabled Boolean? @map("two_factor_enabled")

createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@unique([email])
@@map("user")
}

model Session {
id String @id
userId String @map("user_id")
token String

expiresAt DateTime @map("expires_at")
ipAddress String? @map("ip_address")
userAgent String? @map("user_agent")

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@map("session")
}

model Account {
id String @id
userId String @map("user_id")
accountId String @map("account_id")
providerId String @map("provider_id")

scope String?
password String?

accessToken String? @map("access_token")
refreshToken String? @map("refresh_token")
idToken String? @map("id_token")

accessTokenExpiresAt DateTime? @map("access_token_expires_at")
refreshTokenExpiresAt DateTime? @map("refresh_token_expires_at")

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@map("account")
}
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("POSTGRES_URL")
}

model User {
id String @id
name String
email String
emailVerified Boolean @map("email_verified")

image String?

sessions Session[]
accounts Account[]
passkeys Passkey[]

twofactors TwoFactor[]
twoFactorEnabled Boolean? @map("two_factor_enabled")

createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@unique([email])
@@map("user")
}

model Session {
id String @id
userId String @map("user_id")
token String

expiresAt DateTime @map("expires_at")
ipAddress String? @map("ip_address")
userAgent String? @map("user_agent")

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@map("session")
}

model Account {
id String @id
userId String @map("user_id")
accountId String @map("account_id")
providerId String @map("provider_id")

scope String?
password String?

accessToken String? @map("access_token")
refreshToken String? @map("refresh_token")
idToken String? @map("id_token")

accessTokenExpiresAt DateTime? @map("access_token_expires_at")
refreshTokenExpiresAt DateTime? @map("refresh_token_expires_at")

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@map("account")
}
model Verification {
id String @id
identifier String
value String
expiresAt DateTime @map("expires_at")

createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@map("verification")
}

model TwoFactor {
id String @id
userId String @map("user_id")

secret String
backupCodes String @map("backup_codes")

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@map("two_factor")
}

model Passkey {
id String @id
userId String @map("user_id")

name String?
publicKey String @map("public_key")

credentialID String @map("credential_id")
counter Int
deviceType String @map("device_type")
backedUp Boolean @map("backed_up")
transports String?

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

createdAt DateTime? @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")

@@map("passkey")
}
model Verification {
id String @id
identifier String
value String
expiresAt DateTime @map("expires_at")

createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@map("verification")
}

model TwoFactor {
id String @id
userId String @map("user_id")

secret String
backupCodes String @map("backup_codes")

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@map("two_factor")
}

model Passkey {
id String @id
userId String @map("user_id")

name String?
publicKey String @map("public_key")

credentialID String @map("credential_id")
counter Int
deviceType String @map("device_type")
backedUp Boolean @map("backed_up")
transports String?

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

createdAt DateTime? @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")

@@map("passkey")
}

Did you find this page helpful?