© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•13mo ago•
1 reply
Asperiuns

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 }
    );
  }
}
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 }
    );
  }
}
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 Session Management
SupabaseSSupabase / help-and-questions
4y ago
how to make proper protected routes with Supabase in next JS
SupabaseSSupabase / help-and-questions
4y ago
Supabase with Next.js 13
SupabaseSSupabase / help-and-questions
4y ago
Supabase Auth with Next.js
SupabaseSSupabase / help-and-questions
4y ago