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

Stale auth after succesful sign-in #4143

Open
4 tasks done
joelbqz opened this issue Sep 10, 2024 · 5 comments
Open
4 tasks done

Stale auth after succesful sign-in #4143

joelbqz opened this issue Sep 10, 2024 · 5 comments
Labels
needs-triage A ticket that needs to be triaged by a team member

Comments

@joelbqz
Copy link

joelbqz commented Sep 10, 2024

Preliminary Checks

Reproduction

https://github.com/clerk/clerk-nextjs-demo-app-router

Publishable key

pk_test_aW5zcGlyZWQtbXVkZmlzaC02MC5jbGVyay5hY2NvdW50cy5kZXYk

Description

Repro steps:

  1. clone your nextjs starter
  2. update .env.local with NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY
  3. run
  4. sign-in with Google
  5. you will see stale session: no indication the user is already signed in
  6. hard refresh
  7. now you will see the user is logged in

Environment

System:
    OS: macOS 14.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 88.94 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.7.3 - ~/.nvm/versions/node/v21.7.3/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v21.7.3/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v21.7.3/bin/npm
    pnpm: 9.5.0 - ~/.nvm/versions/node/v21.7.3/bin/pnpm
    bun: 1.1.18 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 125.1.66.118
    Chrome: 128.0.6613.120
    Edge: 128.0.2739.67
    Safari: 17.1
  npmPackages:
    @clerk/nextjs: ^5.1.5 => 5.1.5
    @types/node: ^20.11.0 => 20.12.7
    @types/react: ^18.2.47 => 18.2.79
    @types/react-dom: ^18.2.18 => 18.2.25
    @types/react-syntax-highlighter: ^15.5.11 => 15.5.11
    autoprefixer: ^10.4.16 => 10.4.19
    clsx: ^2.1.1 => 2.1.1
    next: ^14.2.3 => 14.2.3
    postcss: ^8.4.33 => 8.4.38
    prism-react-renderer: ^2.3.1 => 2.3.1
    react: ^18.3.1 => 18.3.1
    react-dom: ^18.3.1 => 18.3.1
    react-syntax-highlighter: ^15.5.0 => 15.5.0
    tailwindcss: ^3.4.1 => 3.4.3
    typescript: ^5.3.3 => 5.4.5
@joelbqz joelbqz added the needs-triage A ticket that needs to be triaged by a team member label Sep 10, 2024
@devharsh2k4
Copy link

Hey can i get assigned?

@alexcarpenter
Copy link
Member

@joelbqz I am not able to replicate. Following the steps you mention, logging in with google, I am properly logged in and see the Sign In button is replaced with the signed in button Dashboard. Is this still an issue you are seeing?

@joelbqz
Copy link
Author

joelbqz commented Oct 8, 2024

@joelbqz I am not able to replicate. Following the steps you mention, logging in with google, I am properly logged in and see the Sign In button is replaced with the signed in button Dashboard. Is this still an issue you are seeing?

hey I just realized that issue happened only if these vars were not set

NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
# NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard
# NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard

@MaxiSantos
Copy link

MaxiSantos commented Nov 16, 2024

@joelbqz I am not able to replicate. Following the steps you mention, logging in with google, I am properly logged in and see the Sign In button is replaced with the signed in button Dashboard. Is this still an issue you are seeing?

hey I just realized that issue happened only if these vars were not set

NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
# NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard
# NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard

Thanks for sharing this. I'm also using NEXT_PUBLIC_CLERK_SIGN_UP_FORCE_REDIRECT_URL and after commenting it now works. I was redirecting user to an onboarding page and there I had <UserProfile /> which was giving me the following error:

  • cannot render unless a user is signed in *

edit: using "next": "15.0.3", and "@clerk/nextjs": "^6.3.1", turbopack for nextjs

@MaxiSantos
Copy link

@joelbqz hey I was doing a custom onboarding and after following this tutorial https://clerk.com/docs/guides/add-onboarding-flow#add-custom-claims-to-your-session-token (the tutorial by itself didn't work) I've found on that same toturial some links to a github repo and there I've found this line: const { isLoaded, user } = useUser();

In my case I was having some issue with UserProfile from clerk not rendered on onboardingPage because of the error you mentioned. But now I'm conditionally rendering UserProfile using isLoaded prop and no wI don't need to refresh. I know its ugly but this issue may be related with redirections/rehydratation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage A ticket that needs to be triaged by a team member
Projects
None yet
Development

No branches or pull requests

4 participants