Check auth status in NextJS Server Action?

I need to check the users auth status in a NextJS Server Action. If the user is authenticated I make an expensive API call to a non-Supabase service so I cant use the normal RLS stuff.

I've moved over to using the SSR package. This is what I have on the client:

import { createBrowserClient } from "@supabase/ssr";
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!!;
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!!;
const supabase = createBrowserClient(supabaseUrl, supabaseKey);
export default supabase;


And in my server action:
'use server'
import { createServerClient, type CookieOptions } from "@supabase/ssr";
import { cookies } from "next/headers";

export async function serverAction(){
  const cookieStore = cookies();
  const supabase = createServerClient(supabaseUrl, supabaseKey, {
    cookies: {
      get(name: string) {
        return cookieStore.get(name)?.value;
      },
      set(name: string, value: string, options: CookieOptions) {
        cookieStore.set({ name, value, ...options });
      },
      remove(name: string, options: CookieOptions) {
        cookieStore.set({ name, value: "", ...options });
      },
    },
  });
  console.log(supabase)
}


I assumed that there would be some property on the supabase object that tells me if the user is logged in, is that correct? It's a huge object so Im not sure which property to use.

I figured it would be something like this:
if(supabase.isLoggedIn){
  expensiveApiCall()
}
Was this page helpful?