t3 app + nextauth
I have setup t3 app with nextauth + prisma + app directory ... Are there any example of protected routes and authentication ?
12 Replies
here is an example page
i want to access this page only if signed in
here is my trpc procedure ...
@srajith I’m not seeing what about this is specific to app dir, is any of it specific to app dir?
i'm confused how to show the
/
page only if logged in, otherwise goto login pageWhat you can do is if the query returns an unauthorized error, to redirect the user to the login page
Or you can use middleware to check if the user is authed, and if they aren’t to redirect them
oh, middleware sounds good any example for it ?
Or you can server side render the page using RSCs and redirect them server side
Securing pages and API routes | NextAuth.js
You can easily protect client and server side rendered pages and API routes with NextAuth.js.
this was for pages (older nextjs), i'm looking for app router / directory
Look at the middleware section
You’re also using the app directory exactly like the pages directory so the pages directory approach probably still works for you, their app directory approach listed won’t since you’re not rendering server side
okay let me check thanks !