I have been searching through nextjs documentation and I found this thing.
import { getToken } from "next-auth/jwt"
const secret = process.env.NEXTAUTH_SECRET
export default async function handler(req, res) {
// if using `NEXTAUTH_SECRET` env variable, we detect it, and you won't actually need to `secret`
// const token = await getToken({ req })
const token = await getToken({ req, secret })
console.log("JSON Web Token", token)
res.end()
}
This gives you the possibility to get the authentication, but I don't know where to use it or how to implement it in all routes. I think it has to be in the /api/auth/[...nextauth.js] but I haven't found any information about it.
I have all my api routes inside api folder.
Help is needed, thanks in advance!