Upgraded to Next Auth v5

This commit is contained in:
Tom
2024-01-02 07:26:20 +00:00
parent a3352af981
commit 4505654a05
24 changed files with 283 additions and 227 deletions

View File

@@ -1,7 +1,6 @@
import { db } from "@/lib/db"
import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { generateToken } from "../token/route";
import { auth } from "@/auth";
import fetchUserUsingAPI from "@/lib/validate-api";
@@ -16,7 +15,7 @@ export async function GET(req: Request) {
export async function POST(req: Request) {
try {
const session = await getServerSession()
const session = await auth()
const user = session?.user?.name
if (!user) {
return new NextResponse("Internal Error", { status: 401 })
@@ -24,26 +23,26 @@ export async function POST(req: Request) {
const exist = await db.user.findFirst({
where: {
username: user.toLowerCase() as string
name: user
}
});
if (exist) {
return NextResponse.json({
id: exist.id,
username: exist.username
username: exist.name
});
}
const newUser = await db.user.create({
data: {
username: user.toLowerCase() as string,
name: user,
}
});
return NextResponse.json({
id: newUser.id,
username: newUser.username
username: newUser.name
});
} catch (error) {
console.log("[ACCOUNT]", error);