data.session from supabase.auth.getSession() is always null.

So... I consider myself a javascript/typescript newbie but I've been using supabase for several months now just fine.

I've recently started a new project in which I installed the latest version of supabase.js which uses the new javascript v2.0 release and no matter what I try data.session from supabase.auth.getSession() is always
null
.

To be specific, I'm using "@supabase/supabase-js": "^2.2.1".


This is the code I'm trying to run:

const options = { auth: { autoRefreshToken: true, persistSession: true } }
const supabase = createClient(env.SB_URL, env.SB_ANON_KEY, options)

const login = async () => {
  const { data, error } = await supabase.auth.getSession()
 
  if (error) {
    console.error(error)
    return false
  }

  if (data.session == null) {
    console.log("here")
    const { data, error } = await supabase.auth.signInWithPassword({
      email: env.USER,
      password: env.PASS,
    })
    if (error) {
      console.error(error)
      return false
    }
  //I've printed data here, All seems fine.
  }

  //debugging here my session:
  console.log(await supabase.auth.getSession())
  return true
}

I've also tried using supabase.getUser() but the result is the same, it's always
null
.

What am I doing wrong? :S
Was this page helpful?