Failed to get session, when remember me is checked

im on latest version v.1.1.14 im using drizzle + postgress So when ever remember me is checked i get the error {"message":"Failed to get session","code":"FAILED_TO_GET_SESSION"} My auth.ts config
export const auth = betterAuth({
emailVerification: {
sendOnSignUp: true,
autoSignInAfterVerification: true,
sendVerificationEmail: async ({ user, url }) => {
await sendEmailVerification({
email: user.email,
url,
});
},
},
emailAndPassword: {
enabled: true,
minPasswordLength: 8,
maxPasswordLength: 40,
sendOnSignUp: true,
sendResetPassword: async ({ user, url }) => {
await sendForgetPassword({
email: user.email,
url,
});
},
password: {
hash: async (password) => await Bun.password.hash(password),
verify: async ({ hash, password }) =>
await Bun.password.verify(password, hash),
},
},
trustedOrigins: ["http://localhost:3000"],
plugins: [
oneTap({
disableSignup: true,
}),
username(),
admin(),
openAPI(),
twoFactor(),
organization({
organizationLimit: 1,
}),
],

database: drizzleAdapter(db, {
provider: "pg",
usePlural: true,
}),
session: {
expiresIn: 60 * 60 * 24 * 30,
updateAge: 0,
cookieCache: {
enabled: false,
},
},
socialProviders: {
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
},
},
});
export const auth = betterAuth({
emailVerification: {
sendOnSignUp: true,
autoSignInAfterVerification: true,
sendVerificationEmail: async ({ user, url }) => {
await sendEmailVerification({
email: user.email,
url,
});
},
},
emailAndPassword: {
enabled: true,
minPasswordLength: 8,
maxPasswordLength: 40,
sendOnSignUp: true,
sendResetPassword: async ({ user, url }) => {
await sendForgetPassword({
email: user.email,
url,
});
},
password: {
hash: async (password) => await Bun.password.hash(password),
verify: async ({ hash, password }) =>
await Bun.password.verify(password, hash),
},
},
trustedOrigins: ["http://localhost:3000"],
plugins: [
oneTap({
disableSignup: true,
}),
username(),
admin(),
openAPI(),
twoFactor(),
organization({
organizationLimit: 1,
}),
],

database: drizzleAdapter(db, {
provider: "pg",
usePlural: true,
}),
session: {
expiresIn: 60 * 60 * 24 * 30,
updateAge: 0,
cookieCache: {
enabled: false,
},
},
socialProviders: {
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
},
},
});
my auth-client.ts
export const authClient = createAuthClient({
plugins: [
usernameClient(),
magicLinkClient(),
organizationClient(),
twoFactorClient(),
],
fetchOptions: {
onError(e) {
if (e.error.status === 429) {
toast.error("Too many requests. Please try again later.");
}
},
},
});
export const authClient = createAuthClient({
plugins: [
usernameClient(),
magicLinkClient(),
organizationClient(),
twoFactorClient(),
],
fetchOptions: {
onError(e) {
if (e.error.status === 429) {
toast.error("Too many requests. Please try again later.");
}
},
},
});
No description
1 Reply
Kabeer
KabeerOP3mo ago
My bad. wierd but i had this database hook to update lastActive of user
databaseHooks: {
session: {
update: {
before: async (session) => {
await db
.update(users)
.set({
lastActive: new Date(),
})
.where(eq(users.id, session.userId!));
},
},
},
},
databaseHooks: {
session: {
update: {
before: async (session) => {
await db
.update(users)
.set({
lastActive: new Date(),
})
.where(eq(users.id, session.userId!));
},
},
},
},
In before session just contained expiresAt after updating to after was getting full session object and everything worked as expected.

Did you find this page helpful?