© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•8mo ago•
2 replies
DizoR

Supabase Auth, get a code instead of session

Hello everybody,

I'm using Supbase DB et Auth with Nextjs (front) and Nestjs (back)

My case is I symply log with google
      const { error } = await supabase.auth.signInWithOAuth({
        provider,
        options: {
          redirectTo: `${window.location.origin}/auth/callback`,
        },
      });
      const { error } = await supabase.auth.signInWithOAuth({
        provider,
        options: {
          redirectTo: `${window.location.origin}/auth/callback`,
        },
      });


And and get the response in a callback
export default function AuthCallback() {
  const router = useRouter();
  const cookies = useCookies();

  useEffect(() => {
    const handleAuthCallback = async () => {
      try {
        // Get the session from the URL hash
        const { data, error } = await supabase.auth.getSession();
export default function AuthCallback() {
  const router = useRouter();
  const cookies = useCookies();

  useEffect(() => {
    const handleAuthCallback = async () => {
      try {
        // Get the session from the URL hash
        const { data, error } = await supabase.auth.getSession();


It's working fine ... but I found this function
supabase.auth.exchangeCodeForSession(String(code))
supabase.auth.exchangeCodeForSession(String(code))


Which is better because I would like to get the code in the fronted and get the JWT in the backend, and share only few fields encrypted (more safe)

So the callback url contains the entire session
Is there a solution to change it to a code instead ?
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 instead of Auth0?
SupabaseSSupabase / help-and-questions
7mo ago
supabase.auth.session() Error
SupabaseSSupabase / help-and-questions
4y ago
Supabase.auth.exchangeCodeForSession doesn't persist session
SupabaseSSupabase / help-and-questions
3y ago
Session from `supabase.auth.exchangeCodeForSession()` not persisting
SupabaseSSupabase / help-and-questions
3y ago