From d7fd124dc6e9a179072e7dbc67e749f619baccca Mon Sep 17 00:00:00 2001 From: Riccardo Date: Wed, 26 Jun 2024 18:49:28 +0200 Subject: [PATCH] feat: attempt to register new user --- .env.example | 3 ++- app/api/{protected => }/register/route.ts | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) rename app/api/{protected => }/register/route.ts (53%) diff --git a/.env.example b/.env.example index 474c321..2a8d1f0 100644 --- a/.env.example +++ b/.env.example @@ -6,4 +6,5 @@ AUTH0_SECRET=somerandomstringtouseasasecret AUTH0_BASE_URL=http://localhost:3000 AUTH0_CLIENT_ID="" AUTH0_CLIENT_SECRET="" -AUTH0_DOMAIN="" \ No newline at end of file +AUTH0_DOMAIN="" +AUTH0_API_SECRET_KEY="" \ No newline at end of file diff --git a/app/api/protected/register/route.ts b/app/api/register/route.ts similarity index 53% rename from app/api/protected/register/route.ts rename to app/api/register/route.ts index a5d2c17..e9fbd4d 100644 --- a/app/api/protected/register/route.ts +++ b/app/api/register/route.ts @@ -1,11 +1,18 @@ -import { getSession, withApiAuthRequired } from '@auth0/nextjs-auth0'; import prisma from '@prisma/prisma'; import { NextRequest, NextResponse } from 'next/server'; -export const POST = withApiAuthRequired(async (request: NextRequest) => { - const session = await getSession(); +export const POST = async (request: NextRequest) => { + 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(); console.log('request', request, 'body', body); @@ -28,4 +35,4 @@ export const POST = withApiAuthRequired(async (request: NextRequest) => { } return NextResponse.json({ message: email }); -}); +};