mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Login Route with JWT
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import bcrypt from 'bcryptjs';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import prisma from "@/app/prisma";
|
||||
|
||||
interface Body {
|
||||
@@ -31,7 +32,13 @@ export async function POST(request: NextRequest) {
|
||||
return NextResponse.json({ error: "Invalid password" }, { status: 401 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Login successful" }, { status: 200 });
|
||||
if(!process.env.JWT_SECRET) {
|
||||
return NextResponse.json({ error: "No JWT secret found" }, { status: 500 });
|
||||
}
|
||||
|
||||
const token = jwt.sign({ id: user.id }, process.env.JWT_SECRET, { expiresIn: "7d" });
|
||||
|
||||
return NextResponse.json({ message: "Login successful", token }, { status: 200 });
|
||||
|
||||
} catch (error: any) {
|
||||
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
|
||||
|
||||
Reference in New Issue
Block a user