feat: attempt to register new user

This commit is contained in:
Riccardo
2024-06-26 18:49:28 +02:00
parent 2076668eab
commit d7fd124dc6
2 changed files with 14 additions and 6 deletions

View File

@@ -7,3 +7,4 @@ AUTH0_BASE_URL=http://localhost:3000
AUTH0_CLIENT_ID="" AUTH0_CLIENT_ID=""
AUTH0_CLIENT_SECRET="" AUTH0_CLIENT_SECRET=""
AUTH0_DOMAIN="" AUTH0_DOMAIN=""
AUTH0_API_SECRET_KEY=""

View File

@@ -1,11 +1,18 @@
import { getSession, withApiAuthRequired } from '@auth0/nextjs-auth0';
import prisma from '@prisma/prisma'; import prisma from '@prisma/prisma';
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
export const POST = withApiAuthRequired(async (request: NextRequest) => { export const POST = async (request: NextRequest) => {
const session = await getSession(); const authHeader = request.headers.get('Authorization');
console.log('Session', session); if (!authHeader || !authHeader.startsWith('Bearer ')) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const token = authHeader.split(' ')[1];
if (token !== process.env.AUTH0_API_SECRET_KEY) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const body = await request.json(); const body = await request.json();
console.log('request', request, 'body', body); console.log('request', request, 'body', body);
@@ -28,4 +35,4 @@ export const POST = withApiAuthRequired(async (request: NextRequest) => {
} }
return NextResponse.json({ message: email }); return NextResponse.json({ message: email });
}); };