user session null

Hi all, I searched and saw a few posts related to my problem but the solution was not enough so I decided to make my own post. I am trying out Better-Auth with Prisma.

Problem: I don't see user session after signing up or logging in. I am able to see the db populate with the information + session data.

What I'm trying to do:
  1. sign up / login
  2. redirect to a different page, i.e / -> /setup
  3. do stuff.
Here is my current code for the configuration:

import { betterAuth } from 'better-auth';
import { prismaAdapter } from "better-auth/adapters/prisma";
import { prisma } from '../../prismdb/prismdb';

export const auth = betterAuth({
    database: prismaAdapter(prisma, {
      provider: "postgresql",      
    }),    
    trustedOrigins: [`localhost`],
    advanced: {
      database: { useNumberId: true },
      crossSubDomainCookies: {
        enabled: true,
        domain: "localhost",
      },
      defaultCookieAttributes: {
        secure: true,
        httpOnly: true,
        sameSite: "none",
        partitioned: true,
      },
    },
    emailAndPassword: {
      enabled: true, 
    },   
    session: {
      cookieCache: {
        enabled: true,
      }
    }
});

export async function signUp(email: string, password: string, image: string | null = null) {
  const result = await auth.api.signUpEmail({
    body: { 
      name: "User Name", 
      email,
      password,
      image,
      callbackURL: "/setup"
    },  
  });

  return result;
}

export async function signIn(email: string, password: string) {
  return await auth.api.signInEmail({
    body: { 
      email, 
      password,
      callbackURL: "/setup"
    }
  });
}

export async function signOut() {
  await auth.api.signOut({
    headers: []
  });
}
Was this page helpful?