feat: add middleware route protection
This commit is contained in:
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
## To do
|
## To do
|
||||||
|
|
||||||
- [ ] Add user authentication
|
- [ ] Add user creation in database
|
||||||
|
- [ ] Add user profile and settings (i.e. language)
|
||||||
- [ ] Add user roles
|
- [ ] Add user roles
|
||||||
- [ ] Add user permissions
|
- [ ] Add user permissions
|
||||||
- [ ] Add user profile
|
|
||||||
- [ ] Add user notifications and emails
|
- [ ] Add user notifications and emails
|
||||||
- [ ] Add user invoices
|
- [ ] Add user invoices
|
||||||
- [ ] Add cron jobs to import data
|
- [ ] Add cron jobs to import data
|
||||||
|
|||||||
28
app/api/signup/route.ts
Normal file
28
app/api/signup/route.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
export default async function handler(
|
||||||
|
req: NextApiRequest,
|
||||||
|
res: NextApiResponse
|
||||||
|
) {
|
||||||
|
if (req.method === 'POST') {
|
||||||
|
const { email } = req.body;
|
||||||
|
try {
|
||||||
|
const user = await prisma.user.create({
|
||||||
|
data: {
|
||||||
|
email
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return res.status(200).json(user);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to create user:', error);
|
||||||
|
return res.status(500).json({ error: 'Failed to create user' });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Handle any other HTTP method
|
||||||
|
res.setHeader('Allow', ['POST']);
|
||||||
|
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||||
|
}
|
||||||
|
}
|
||||||
7
middleware.ts
Normal file
7
middleware.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { withMiddlewareAuthRequired } from '@auth0/nextjs-auth0/edge';
|
||||||
|
|
||||||
|
export default withMiddlewareAuthRequired();
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
matcher: ['/module/:path*', '/user']
|
||||||
|
};
|
||||||
@@ -16,7 +16,7 @@ enum ModuleType {
|
|||||||
|
|
||||||
model User {
|
model User {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
name String
|
name String?
|
||||||
email String @unique
|
email String @unique
|
||||||
deleted Boolean @default(false)
|
deleted Boolean @default(false)
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|||||||
Reference in New Issue
Block a user