Next-auth How to redirect signed in users?

56 Views Asked by At

I am trying to protect my /sign-in page from signed in user by redirecting them to another page. However I have been stuck with this problem for a while now. I have found this stack overflow discussion, however both answers provided do not work.

Here is what my current middleware looks like. All it does right now is protecting my private pages to non signed users.

How could I extend this middleware to redirect users to a specific page if they are signed in ?

export { default } from "next-auth/middleware";

export const config = { matcher: ["/dashboard/:path*", "/exercises/:path*"] };

Additional information

To clarify here is what I am trying to do.

I am trying to protect the routes :

  • /dashboard /exercises/* - Those two routes should only be accessible by signed in users
  • / /sign-in /verify-request - Those three routes should only be accessible by not signed in users

Full source code

https://github.com/augustinsorel/gym-graphs

0

There are 0 best solutions below