t3 app + nextauth

I have setup t3 app with nextauth + prisma + app directory ... Are there any example of protected routes and authentication ?
12 Replies
srajith
srajithOP12mo ago
here is an example page
No description
srajith
srajithOP12mo ago
i want to access this page only if signed in
srajith
srajithOP12mo ago
here is my trpc procedure ...
No description
Rhys
Rhys12mo ago
@srajith I’m not seeing what about this is specific to app dir, is any of it specific to app dir?
srajith
srajithOP12mo ago
i'm confused how to show the / page only if logged in, otherwise goto login page
Rhys
Rhys12mo ago
What 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
srajith
srajithOP12mo ago
oh, middleware sounds good any example for it ?
Rhys
Rhys12mo ago
Or you can server side render the page using RSCs and redirect them server side
Rhys
Rhys12mo ago
Securing pages and API routes | NextAuth.js
You can easily protect client and server side rendered pages and API routes with NextAuth.js.
srajith
srajithOP12mo ago
this was for pages (older nextjs), i'm looking for app router / directory
Rhys
Rhys12mo ago
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
srajith
srajithOP12mo ago
okay let me check thanks !
Want results from more Discord servers?
Add your server