Removed passwordHash when returning user after login
This commit is contained in:
parent
9124274603
commit
4cdeb5525a
@ -23,8 +23,6 @@ export async function POST(req: Request) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (user && bcryptjs.compareSync(password, user.passwordHash)) {
|
if (user && bcryptjs.compareSync(password, user.passwordHash)) {
|
||||||
// todo remove password from returned user
|
|
||||||
|
|
||||||
// get user and relations
|
// get user and relations
|
||||||
user = await prisma.user.findUnique({
|
user = await prisma.user.findUnique({
|
||||||
where: { id: user.id },
|
where: { id: user.id },
|
||||||
@ -42,6 +40,7 @@ export async function POST(req: Request) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const { passwordHash, ...userSansHash } = user!;
|
||||||
|
|
||||||
const secret = new TextEncoder().encode(env.JWT_SECRET_KEY);
|
const secret = new TextEncoder().encode(env.JWT_SECRET_KEY);
|
||||||
const token = await new SignJWT({ userId: user!.id })
|
const token = await new SignJWT({ userId: user!.id })
|
||||||
@ -49,7 +48,7 @@ export async function POST(req: Request) {
|
|||||||
.setExpirationTime("2w")
|
.setExpirationTime("2w")
|
||||||
.sign(secret);
|
.sign(secret);
|
||||||
|
|
||||||
const response = NextResponse.json({ message: "Login successful!", user, token }, { status: 200 });
|
const response = NextResponse.json({ message: "Login successful!", user: userSansHash, token }, { status: 200 });
|
||||||
response.cookies.set("jwt", token, {
|
response.cookies.set("jwt", token, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: process.env.NODE_ENV === "production",
|
secure: process.env.NODE_ENV === "production",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user