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

The <SignIn/> component cannot render when a user is already signed in, unless the application allows multiple sessions. Since a user is signed in and this application only allows a single session, Clerk is redirecting to the afterSignIn URL instead. (This notice only appears in development) #11

Open
Victorosayame opened this issue Aug 9, 2024 · 7 comments

Comments

@Victorosayame
Copy link

i keep getting this error even when i did everything correctly, i also cloned yours,created a new clerk and liveblocks account and still gets the same error.

The component cannot render when a user is already signed in, unless the application allows multiple sessions. Since a user is signed in and this application only allows a single session, Clerk is redirecting to the afterSignIn URL instead.
(This notice only appears in development)
Screenshot (74)
Screenshot (74)
Screenshot (74)

@FrBosquet
Copy link

I have the same issue. Please help, is so annoying

@AbhinavSharma486
Copy link

I have the same issue. Please help, is so annoying

i also have same issue

@jordanskizash
Copy link

Same issue, only in development.

@FrBosquet
Copy link

I solved it for my case:

  • Turned my sign in component to a client side one, using 'use client'
  • Check if there is an user with useUser, redirect to my private dashboard if positive
  • Show the log in component other-wise

For some reason the sign in page is being sent to the client without an user before hydration, after hydration there is an user and thats where the issue happens.

@shabazs453
Copy link

@FrBosquet , can you sent your sign in component's code? please.

@shabazs453
Copy link

@FrBosquet
I changed my middleware file to following

**import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
const isPublicRoute = createRouteMatcher(["/sign-in(.)", "/sign-up(.)"]);

export default clerkMiddleware((auth, request) => {
if (!isPublicRoute(request)) {
auth().protect();
}
});

export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
"/((?!_next|[^?]\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).)",
// Always run for API routes
"/(api|trpc)(.*)",
],
};**

It checks user authentication on server side itself.

So I removed the redirect to sign-in page from home page and changed it to return null.

import Link from "next/link";
import { redirect } from "next/navigation";

const Home = async () => {
const clerkUser = await currentUser();
if (!clerkUser) return null;

const roomDocuments = await getDocuments(
clerkUser?.emailAddresses[0]?.emailAddress
);

Also you have to correctly synchronize the system time to actual time since tokens do not work properly when being passed to clerk server.

@Pratik1805
Copy link

Adjust your system time correctly according to your time zone in your settings, worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants