© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
1 reply
JVG

Signup from API: 401: invalid claim: missing sub claim

I'm running a NextJS server to sell products. When my user buys a product with Stripe, I have a webhook which receives the payment info and client info (email + name).

I want to sign the user up and send them a magic link after they make a purchase. From what I can see, this has to happen from within my webhook code.

I'm doing:

  const supabase = new SupabaseClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL,
    process.env.SUPABASE_SERVICE_ROLE_KEY
  );

        await supabase.auth.signInWithOtp({
          email,
          options: {
            shouldCreateUser: true,
            emailRedirectTo: redirectURL,
          },
        });
  const supabase = new SupabaseClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL,
    process.env.SUPABASE_SERVICE_ROLE_KEY
  );

        await supabase.auth.signInWithOtp({
          email,
          options: {
            shouldCreateUser: true,
            emailRedirectTo: redirectURL,
          },
        });


This works fine and the link successfully goes to the user's email. HOWEVER, when the user clicks the link, my callback handler does:

const requestUrl = new URL(request.url);
const code = requestUrl.searchParams.get("code");
const requestUrl = new URL(request.url);
const code = requestUrl.searchParams.get("code");


there is NO code sent from Supabase, it's null. When I sign up a user from the client side of the website then the code works fine.

I also see this error in my supabase logs:
{"component":"api","error":"401: invalid claim: missing sub claim","level":"info","method":"GET","msg":"401: invalid claim: missing sub claim","path":"/user","referer":"http://localhost:3000/","remote_addr":"180.150.37.140","time":"2024-01-12T00:54:59Z","timestamp":"2024-01-12T00:54:59Z"}
{"component":"api","error":"401: invalid claim: missing sub claim","level":"info","method":"GET","msg":"401: invalid claim: missing sub claim","path":"/user","referer":"http://localhost:3000/","remote_addr":"180.150.37.140","time":"2024-01-12T00:54:59Z","timestamp":"2024-01-12T00:54:59Z"}
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

401: invalid claim: missing sub claim
SupabaseSSupabase / help-and-questions
3y ago
Supabase OAuth (Slack) throws "invalid claim: missing sub claim"
SupabaseSSupabase / help-and-questions
3y ago
Missing sub claim when try to getUser after setSession
SupabaseSSupabase / help-and-questions
4y ago
Cannot signin/signup 401 unauthorized
SupabaseSSupabase / help-and-questions
3y ago