fix: protect correct routes
This commit is contained in:
22
app/api/protected/module/[id]/route.ts
Normal file
22
app/api/protected/module/[id]/route.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: number } }
|
||||
) {
|
||||
return NextResponse.json(`GET ${params.id}`);
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: number } }
|
||||
) {
|
||||
return NextResponse.json(`PUT ${params.id}`);
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: number } }
|
||||
) {
|
||||
return NextResponse.json(`DELETE ${params.id}`);
|
||||
}
|
||||
9
app/api/protected/module/route.ts
Normal file
9
app/api/protected/module/route.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(request: NextRequest, response: NextResponse) {
|
||||
return NextResponse.json('GET request');
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest, response: NextResponse) {
|
||||
return NextResponse.json('POST request');
|
||||
}
|
||||
11
app/api/protected/profile/route.ts
Normal file
11
app/api/protected/profile/route.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { getSession, withApiAuthRequired } from '@auth0/nextjs-auth0';
|
||||
|
||||
const GET = withApiAuthRequired(async () => {
|
||||
const session = await getSession();
|
||||
|
||||
return NextResponse.json(session?.user);
|
||||
});
|
||||
|
||||
export { GET };
|
||||
31
app/api/protected/register/route.ts
Normal file
31
app/api/protected/register/route.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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();
|
||||
|
||||
console.log('Session', session);
|
||||
|
||||
const body = await request.json();
|
||||
console.log('request', request, 'body', body);
|
||||
|
||||
const { email } = await request.json();
|
||||
|
||||
if (email) {
|
||||
await prisma.user.upsert({
|
||||
create: {
|
||||
email
|
||||
},
|
||||
update: {
|
||||
updatedAt: new Date()
|
||||
},
|
||||
where: {
|
||||
deleted: false,
|
||||
email
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: email });
|
||||
});
|
||||
Reference in New Issue
Block a user