© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
17 replies
Torwent🐝

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
javascript v2.0
release and no matter what I try
data.session
data.session
from
supabase.auth.getSession()
supabase.auth.getSession()
is always
null
null
.

To be specific, I'm using
"@supabase/supabase-js": "^2.2.1"
"@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
}
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()
supabase.getUser()
but the result is the same, it's always
null
null
.

What am I doing wrong? :S
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

supabase auth.getUser always returns null
SupabaseSSupabase / help-and-questions
4y ago
supabase {session: null, user: null } error using supabase auth signup api?
SupabaseSSupabase / help-and-questions
8mo ago
supabase.auth.session() Error
SupabaseSSupabase / help-and-questions
4y ago
getSession() is null after login?
SupabaseSSupabase / help-and-questions
3y ago