Next.js Discord

Discord Forum

add a searchParam in protectedRoute | nextAuth

Unanswered
Naeemgg posted this in #help-forum
Open in Discord
I have some protected routes configured with next-auth in middleware matcher, My question is assume /dashboardand /account both are protected routes. user comes by clicking a link https://my-web.vercel.app/dashboard and directly redirected to /login as user was unauthorized, So after user loggs in he'll be redirected to /account as I have called the signIn function like this
const res = await signIn("credentials", {redirect:false, email: data.email, password: data.password });
      if(res?.status===200){
        router.push(`/${lang}/account`)
....

all I want is to redirect users from where they came from everytime, For that I thought of adding a searchParam in /login but unable to do it.

2 Replies