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
srajith6mo ago
here is an example page
No description
srajith
srajith6mo ago
i want to access this page only if signed in
srajith
srajith6mo ago
here is my trpc procedure ...
No description
Rhys
Rhys6mo ago
@srajith I’m not seeing what about this is specific to app dir, is any of it specific to app dir?
srajith
srajith6mo ago
i'm confused how to show the / page only if logged in, otherwise goto login page
Rhys
Rhys6mo 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
srajith6mo ago
oh, middleware sounds good any example for it ?
Rhys
Rhys6mo ago
Or you can server side render the page using RSCs and redirect them server side
Rhys
Rhys6mo 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
srajith6mo ago
this was for pages (older nextjs), i'm looking for app router / directory
Rhys
Rhys6mo 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
srajith6mo ago
okay let me check thanks !
Want results from more Discord servers?
Add your server
More Posts