#Is their latest documentation link for Next-auth?
10 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
I've found a recent youtube video in this link which suggests the following folder structure.
Which one is the good starter?
Next-auth is an easy way to get started with authentication in your NextJS App Router application. Let's get it set up, and see how to secure routes, server actions, API routes and client and server API requests!
Code: https://github.com/jherr/next-auth-v5
👉 Upcoming NextJS course: https://pronextjs.dev
👉 Don't forget to subscribe to this chan...
you can see one example for app router here: https://next-auth.js.org/configuration/initialization#route-handlers-app
This is the same for app and pages router: https://next-auth.js.org/configuration/options
And this as well: https://next-auth.js.org/getting-started/example
So the only thing that is handled a bit differently is the folder structure on how to build an api endpoint for next-auth
Thank you for the kind answer.
I've successfully created route.ts file as in the image.
Now I'm trying to use useSession hook in my client-side code, which requires SessionProvider.
But in the document, it recommends using getServerSession instead of SessionProvider. However, I'm not understanding how to properly create those files in which folder.
Could you please simply show a guide for the folder structure?
getServerSession
getServerSession and SessionProvider are two different things. The getServerSession method is for all serverside stuff. The SessionProvider is for all clientside stuff.
You linked a file, that shows how you don't need to pass authOptions around. Because when you want to get the session serverside with getServerSession you need to add the auth options as argument to it: await getServerSession(authOptions).
The step that you linked is optional and only makes an easier function.
This:
const session = await getServerSession(authOptions);
Becomes this (with your helper function):
const session = await getServerSession();
Oh, you mean I can create a @/utils/helper.ts for the code from the document, and use it as you mentioned?
const session = await getServerSession();
import type {
GetServerSidePropsContext,
NextApiRequest,
NextApiResponse,
} from "next"
import type { NextAuthOptions } from "next-auth"
import { getServerSession } from "next-auth"
// You'll need to import and pass this
// to `NextAuth` in `app/api/auth/[...nextauth]/route.ts`
export const config = {
providers: [], // rest of your config
} satisfies NextAuthOptions
// Use it in server contexts
export function auth(
...args:
| [GetServerSidePropsContext["req"], GetServerSidePropsContext["res"]]
| [NextApiRequest, NextApiResponse]
| []
) {
return getServerSession(...args, config)
}
I haven't ever created the helper myself, so idk. I guess it's https://tryitands.ee/
Ok thank you!
This question has been marked as answered! If you have any other questions, feel free to create another post
[Click here](#1277899113123418205 message)