supabase calling supabase.auth.user().id crashes server error 500

in api.js where connection to supabase is made
userDetails() {
  return supabase
  .from('muni_users')
  .select('*')
  .eq('user_id', supabase.auth.user().id);
},


on a page
export async function load() {
  const { data: muni_user, error: bleh } = await db.users.userDetails();
  console.log(muni_user)
};


and this is error I get in terminal while my browser shows ERROR 500
Cannot read properties of null (reading 'id')
TypeError: Cannot read properties of null (reading 'id')


What is causing it and how can I pass currently logged in user id to userDetails()? If I hardcode user id which is uuid for that table then it shows me results I am looking for.
Was this page helpful?