Upgraded to Next Auth v5
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user