This commit is contained in:
PxlLoewe
2025-02-15 18:06:21 +01:00
parent 1fba206dbf
commit bb9feaa1cc
14 changed files with 224 additions and 14 deletions

View File

@@ -17,7 +17,7 @@ export const Authorize = ({ service }: { service: Service }) => {
return (
<div className="card-body">
<h1 className="text-4xl font-bold">Unerlaubter Zugriff</h1>
<p>Du greifst von einem ncith genehmigtem Server auf diese URL zu</p>
<p>Du greifst von einem nicht genehmigtem Server auf diese URL zu</p>
</div>
);

View File

@@ -7,6 +7,12 @@ export const services = [
name: 'Leitstellendisposition',
approvedUrls: ['http://localhost:3001'],
},
{
id: '789456',
service: 'desktop',
name: 'Desktop client',
approvedUrls: ['var'],
},
];
export type Service = (typeof services)[number];

View File

@@ -0,0 +1,23 @@
'use client';
import { useSession } from 'next-auth/react';
import Link from 'next/link';
export const Header = () => {
const session = useSession();
console.log(session);
return (
<header className="flex justify-between items-center p-4">
<h1 className="text-2xl font-bold">Hub</h1>
<div>
{session.status === 'authenticated' ? (
<p>{session.data?.user.firstname}</p>
) : (
<Link href="/login">
<button className="btn">Login</button>
</Link>
)}
</div>
</header>
);
};

View File

@@ -0,0 +1,3 @@
export default () => {
return <div>Admin Page</div>;
};

View File

@@ -0,0 +1,28 @@
import { PrismaClient } from '@repo/db';
import { NextRequest, NextResponse } from 'next/server';
import { sign } from 'jsonwebtoken';
export const GET = async (req: NextRequest) => {
const client = new PrismaClient();
const accessToken = req.nextUrl.searchParams.get('token');
if (!accessToken)
return new Response('No access token provided', { status: 400 });
const accessRequest = await client.oAuthToken.findFirst({
where: {
accessToken: accessToken,
},
include: {
user: true,
},
});
if (!accessRequest)
return new Response('Access token not found', { status: 404 });
const jwt = sign(accessRequest.user, process.env.NEXTAUTH_SECRET as string, {
expiresIn: '30d',
});
return Response.json({
user: accessRequest.user,
jwt,
});
};

View File

@@ -1,16 +1,11 @@
import Link from 'next/link';
import { PrismaClient } from '@repo/db';
import { PaginatedTable } from './_components/PaginatedTable';
import { Header } from './_components/ui/Header';
export default async function Home() {
const prisma = new PrismaClient();
return (
<div>
<h1 className="text-5xl">Hub</h1>
<Link href="/logout">
<button className="btn">Logout</button>
</Link>
<Header />
<PaginatedTable
rowsPerPage={10}
prismaModel={'user'}