Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createBrowserClient logs users out if there's a error_description query parameter #74

Open
2 tasks done
christiangenco opened this issue Oct 15, 2024 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@christiangenco
Copy link

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

createBrowserClient from @supabase/ssr will log users out on Next.js on any client-rendered page with an error_description query parameter.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a Supabase project and Next.js app with npx create-next-app -e with-supabase and fill out .env.local with NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY as described on Use Supabase with Next.js
  2. Create a new client component app/frontend/page.js to fetch the user following the template from the starter kit:
"use client";

import { createClient } from "@/utils/supabase/client";
import { useEffect, useState } from "react";

export default function Page() {
  const [user, setUser] = useState(null);
  const supabase = createClient();

  useEffect(() => {
    const getUser = async () => {
      const {
        data: { user },
      } = await supabase.auth.getUser();
      setUser(user);
    };
    getUser();
  }, []);

  return <pre>{JSON.stringify(user, null, 2)}</pre>;
}
  1. Log in at /sign-in
  2. Verify that you're logged in by visiting /frontend and seeing your user data in the pre tag
  3. Add an error_description query parameter with any value (ex: /frontend?error_description=a) and you'll be logged out

I think there are other OAuth-related query parameters that evoke the same bug.

Expected behavior

You should not be logged out.

This was super hard to track down and looks like it's causing other issues involving OAuth flows like Auth: User unexpectedly logs out when linking new OAuth provider fails

System information

  • OS: macOS 14.5
  • Version of supabase-js: 2.45.4
  • Version of Node.js: 18.17.1

Additional context

This bug doesn't happen on server-rendered pages like /protected.

@christiangenco christiangenco added the bug Something isn't working label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant