How does Supabase handle session management when working with Next.JS API routes ?

I made a test application and while the Supabase system works flawlessly with Next.JS Server Actions, the API routes require Access Token validation, so how is the logout process done in this case? Because the logout process does not require any JWT Tokens and how does it know who the current user is ?

Example :

import { supabase } from '../../../utils/supabaseClient';

export async function POST(req) {
  try {
    const { error: signOutError } = await supabase.auth.signOut();

    if (signOutError) {
      return new Response(
        JSON.stringify({error: signOutError.message}),
        { status: 400 }
      );
    }

    return new Response(JSON.stringify({ message: 'Successful' }), {
      status: 200,
    });
  } catch (err) {
    return new Response(
      JSON.stringify({ message: 'Server Error', error: err.message }),
      { status: 500 }
    );
  }
}
Was this page helpful?