Iron-session in NextJS 13 >
Unanswered
127.0.0.1 posted this in #help-forum
So im completely new to NextJS and i decided to use the new app dir.
I have my loginbutton component and my api route for loggin in.
This is the api route.ts:
As you can see this works fine. Is there anyone who can guide me on how to set a session when authenticated is true?
I have my loginbutton component and my api route for loggin in.
This is the api route.ts:
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
export async function POST(req) {
let {usernameValue, passwordValue} = await req.json();
var username = usernameValue
var password = passwordValue
try {
const site = await prisma.users.findFirst({
where: {
username: username,
password: password,
},
});
if (site) {
return Response.json({ authenticated: true })
} else {
return Response.json({ authenticated: false})
}
} catch (error) {
console.error(error);
return Response.json({ authenticated: false, error: 'An error occured.' })
} finally {
await prisma.$disconnect();
}
}As you can see this works fine. Is there anyone who can guide me on how to set a session when authenticated is true?