Hano
PPrisma
•Created by Hano on 2/23/2025 in #help-and-questions
Trying to create simple POST function (Expected double-quoted property name)
import prisma from '@/lib/prisma';
import { NextRequest, NextResponse } from 'next/server';
export async function POST(req: NextRequest) {
const data = await req.json();
const user = await prisma.user.create({
data,
});
return NextResponse.json(user);
}
import prisma from '@/lib/prisma';
import { NextRequest, NextResponse } from 'next/server';
export async function POST(req: NextRequest) {
const data = await req.json();
const user = await prisma.user.create({
data,
});
return NextResponse.json(user);
}
{
"username": "bob",
"email": "[email protected]",
"password": "bob",
}
{
"username": "bob",
"email": "[email protected]",
"password": "bob",
}
SyntaxError: Expected double-quoted property name in JSON at position 80 (line 5 column 1)
at JSON.parse (<anonymous>)
at async POST (app\api\users\route.ts:14:15)
12 |
13 | export async function POST(req: NextRequest) {
> 14 | const data = await req.json();
| ^
15 | console.log(data);
16 | const user = await prisma.user.create({
17 | data,
POST /api/users 500 in 275ms
SyntaxError: Expected double-quoted property name in JSON at position 80 (line 5 column 1)
at JSON.parse (<anonymous>)
at async POST (app\api\users\route.ts:14:15)
12 |
13 | export async function POST(req: NextRequest) {
> 14 | const data = await req.json();
| ^
15 | console.log(data);
16 | const user = await prisma.user.create({
17 | data,
POST /api/users 500 in 275ms
6 replies