useSession weird behaviour
Hi, I have some problems with useSession, it keeps giving me date null even though I am logged in. I'm testing it with dev and turbopack.
This happens when I do a page refresh, so if I logout and log in the hook works, but if I do a page refresh it no longer works returning null.
This happens when I do a page refresh, so if I logout and log in the hook works, but if I do a page refresh it no longer works returning null.
auth-client.tsauth-client.tsimport { createAuthClient } from "better-auth/react";
import { inferAdditionalFields } from "better-auth/client/plugins";
import type { auth } from "@/auth";
export const authClient = createAuthClient({
plugins: [inferAdditionalFields<typeof auth>()],
baseURL: process.env.BETTER_AUTH_URL! // Optional if the API base URL matches the frontend
});
export const { signIn, signOut, useSession, getSession } = authClient;import { createAuthClient } from "better-auth/react";
import { inferAdditionalFields } from "better-auth/client/plugins";
import type { auth } from "@/auth";
export const authClient = createAuthClient({
plugins: [inferAdditionalFields<typeof auth>()],
baseURL: process.env.BETTER_AUTH_URL! // Optional if the API base URL matches the frontend
});
export const { signIn, signOut, useSession, getSession } = authClient;auth.tsauth.tsimport { betterAuth } from 'better-auth'
import { prismaAdapter } from 'better-auth/adapters/prisma'
import { prisma } from './lib/db'
import { sendVerificationMail } from './lib/mail'
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: 'postgresql'
}),
user: {
additionalFields: {
dob: {
type: 'string',
required: true
}
}
},
emailAndPassword: {
enabled: true,
minPasswordLength: 4,
maxPasswordLength: 32,
requireEmailVerification: true
},
emailVerification: {
sendVerificationEmail: async ({ user, url }) => await sendVerificationMail(user.email, url),
sendOnSignUp: true,
autoSignInAfterVerification: true,
},
advanced: {
cookiePrefix: 'diveme'
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string
}
}
})import { betterAuth } from 'better-auth'
import { prismaAdapter } from 'better-auth/adapters/prisma'
import { prisma } from './lib/db'
import { sendVerificationMail } from './lib/mail'
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: 'postgresql'
}),
user: {
additionalFields: {
dob: {
type: 'string',
required: true
}
}
},
emailAndPassword: {
enabled: true,
minPasswordLength: 4,
maxPasswordLength: 32,
requireEmailVerification: true
},
emailVerification: {
sendVerificationEmail: async ({ user, url }) => await sendVerificationMail(user.email, url),
sendOnSignUp: true,
autoSignInAfterVerification: true,
},
advanced: {
cookiePrefix: 'diveme'
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string
}
}
})