router.push from "next/navigation" does not do anything
Answered
Alligator mississippiensis posted this in #help-forum
Alligator mississippiensisOP
router.push from "next/navigation" does not do anything
I am doing something in the context of (this is not the full code, just to describe what I am doing, it is just pseuo code):
I am doing something in the context of (this is not the full code, just to describe what I am doing, it is just pseuo code):
import { useRouter } from 'next/navigation';
const router = useRouter();
return await router.push("/panel/prispevky");Answered by Alligator mississippiensis
await clerk.setActive({
session: signInAttempt.createdSessionId,
organization: null,
});
await clerk.setSession(signInAttempt.createdSessionId, () =>
router.push("/panel/prispevky")
);23 Replies
Alligator mississippiensisOP
When I try next redirect I get:
Login error: Error: NEXT_REDIRECT
at getRedirectError (redirect.js:58:19)
at redirect (redirect.js:69:11)
at onSubmit (page.tsx:48:40)Siberian Rubythroat
Try remove await
router.push("/panel/prispevky");Alligator mississippiensisOP
I tried, still not working.
I also tried not using return still no redirect.
Berylline Hummingbird
Which version are you using? @Alligator mississippiensis
@Berylline Hummingbird Which version are you using? <@644225014261874710>
Alligator mississippiensisOP
Next.js 14.1.0
Berylline Hummingbird
Are you using app router?
Alligator mississippiensisOP
yes
Also btw in my sidebar component router.push works perfectly
I can DM you the source code of the file that the issue is in if you want.
I my sidebar I am doing:
<button onClick={() => signOut(() => router.push("/prihlasenie"))}>@Alligator mississippiensis router.push from "next/navigation" does not do anything
I am doing something in the context of (this is not the full code, just to describe what I am doing, it is just pseuo code):
import { useRouter } from 'next/navigation';
const router = useRouter();
return await router.push("/panel/prispevky");
...return await?
if you return something router.push wont work
if you return something router.push wont work
Alligator mississippiensisOP
I was just trying to see if it helps, to it doesnt work even when I dont use return or await.
so you arent getting routed right?
it would be better for you to send your whole code, just remove things like css and html
Alligator mississippiensisOP
I found the fix.
It has to do with Clerk.
Alligator mississippiensisOP
await clerk.setActive({
session: signInAttempt.createdSessionId,
organization: null,
});
await clerk.setSession(signInAttempt.createdSessionId, () =>
router.push("/panel/prispevky")
);Answer
Alligator mississippiensisOP
I have to set the session to active then using setSession set the sessionId.
As I had a function in my middleware to redirect unprotected routes to login.
So router.psuh was infact working.
but it just redirected back.