Closed AdnanHussainTurki closed 1 month ago
Hi @AdnanHussainTurki thanks for your interest on the project! I updated your code to work with next auth v5. The route will be protected and no need to bring back the env variable or the token. I don't know if this is what you are looking for. More information here
import { auth } from "@/auth";
import { prisma } from "@/lib/db";
import { getIp } from "change/with/your/path";
export const POST = auth(async (req) => {
if (!req.auth) {
return Response.json({ message: "Not authenticated" }, { status: 401 });
}
const currentUser = req.auth.user;
let { slug, input, ip } = await req.json();
ip = getIp(req);
if (!ip) {
return Response.json({ message: "Invalid request" }, { status: 400 });
}
let user: any = null;
if (currentUser) {
user = await prisma.user.findUnique({
where: {
id: currentUser.id,
},
});
}
return Response.json({ message: "ok" }, { status: 200 });
});
Hi,
I am using the starter kit and I must say, It is really awesome and made the startup of the project, absolutely an ease.
Recently, I am facing an issue where the API endpoint is not able to fetch the authenticated user through getToken().
package.json
components/services/service-input-card.tsx
api/jobs/route.tsx
The bareUser and user both come out to be null.
Note: In development, things seem to be working but on Vercel it is not. Possibly some issue with the transition from next-auth to auth.js.
Please guide.