© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•2y ago•
12 replies
adebiyial

AuthApiError: invalid request: both auth code and code verifier should be non-empty

I'm getting this
AuthApiError
AuthApiError
when I
exchangeCodeForSession
exchangeCodeForSession
with
signInWithOAuth({ provider: "google" })
signInWithOAuth({ provider: "google" })
.

Framework: Remix.
Auth package:
@supabase/ssr
@supabase/ssr


My Supabase client is defined as thus:

import {
  createServerClient,
  parseCookieHeader,
  serializeCookieHeader,
} from "@supabase/ssr";

export function getSupabase(request: Request) {
  const headers = new Headers();

  const supabase = createServerClient(
    process.env.SUPABASE_URL!,
    process.env.SUPABASE_ANON_KEY!,
    {
      cookies: {
        getAll() {
          return parseCookieHeader(request.headers.get("Cookie") ?? "");
        },
        setAll(cookiesToSet) {
          cookiesToSet.forEach(({ name, value, options }) =>
            headers.append(
              "Set-Cookie",
              serializeCookieHeader(name, value, options)
            )
          );
        },
      },
    }
  );

  return { supabase, headers };
}
import {
  createServerClient,
  parseCookieHeader,
  serializeCookieHeader,
} from "@supabase/ssr";

export function getSupabase(request: Request) {
  const headers = new Headers();

  const supabase = createServerClient(
    process.env.SUPABASE_URL!,
    process.env.SUPABASE_ANON_KEY!,
    {
      cookies: {
        getAll() {
          return parseCookieHeader(request.headers.get("Cookie") ?? "");
        },
        setAll(cookiesToSet) {
          cookiesToSet.forEach(({ name, value, options }) =>
            headers.append(
              "Set-Cookie",
              serializeCookieHeader(name, value, options)
            )
          );
        },
      },
    }
  );

  return { supabase, headers };
}


My sign-in/up logic is defined in a Remix action as:

const { data, error } = await supabase.auth.signInWithOAuth({
  provider: "google",
  options: {
    redirectTo: `http://localhost:5173/auth/callback`,
  },
});
const { data, error } = await supabase.auth.signInWithOAuth({
  provider: "google",
  options: {
    redirectTo: `http://localhost:5173/auth/callback`,
  },
});


My
auth/callback
auth/callback
's Remix loader is defined as:

export async function loader({ request }: LoaderFunctionArgs) {
  const requestUrl = new URL(request.url);
  const code = requestUrl.searchParams.get("code");

  if (code) {
    const { supabase } = await getSupabase(request);
    const res = await supabase.auth.exchangeCodeForSession(code);

    console.log("*".repeat(33));
    console.log({ res });
  } else {
    console.log("Error...");
  }

  return null;
}
export async function loader({ request }: LoaderFunctionArgs) {
  const requestUrl = new URL(request.url);
  const code = requestUrl.searchParams.get("code");

  if (code) {
    const { supabase } = await getSupabase(request);
    const res = await supabase.auth.exchangeCodeForSession(code);

    console.log("*".repeat(33));
    console.log({ res });
  } else {
    console.log("Error...");
  }

  return null;
}


This is consistent with everything in the docs. I just don't understand why I keep getting the errors:

 data: { user: null, session: null, redirectType: null },
 error: AuthApiError: invalid request: both auth code and code verifier should be non-empty
 data: { user: null, session: null, redirectType: null },
 error: AuthApiError: invalid request: both auth code and code verifier should be non-empty


Even though I can now see the user in the Auth session of the Supabase dashboard 😞
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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

[AuthApiError]: invalid request: both auth code and code verifier should be non-empty
SupabaseSSupabase / help-and-questions
7mo ago
AuthApiError: invalid request: both auth code and code verifier should be non-empty
SupabaseSSupabase / help-and-questions
14mo ago
both auth code and code verifier should be non-empty
SupabaseSSupabase / help-and-questions
3y ago
Social Oauth - both auth code and code verifier should be non-empty
SupabaseSSupabase / help-and-questions
3y ago