oAuth
This commit is contained in:
@@ -26,7 +26,6 @@ export const options: AuthOptions = {
|
||||
id: code.userId,
|
||||
},
|
||||
});
|
||||
console.log(code, user);
|
||||
|
||||
if (!user) return null;
|
||||
|
||||
@@ -43,7 +42,7 @@ export const options: AuthOptions = {
|
||||
maxAge: 30 * 24 * 60 * 60,
|
||||
},
|
||||
|
||||
adapter: PrismaAdapter(prisma),
|
||||
adapter: PrismaAdapter(prisma as any),
|
||||
callbacks: {
|
||||
jwt: async ({ token, user }) => {
|
||||
if (user && 'firstname' in user) {
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
23
apps/hub/app/_components/ui/Header.tsx
Normal file
23
apps/hub/app/_components/ui/Header.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
3
apps/hub/app/admin/page.tsx
Normal file
3
apps/hub/app/admin/page.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
export default () => {
|
||||
return <div>Admin Page</div>;
|
||||
};
|
||||
28
apps/hub/app/api/auth/accessToken/route.ts
Normal file
28
apps/hub/app/api/auth/accessToken/route.ts
Normal 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,
|
||||
});
|
||||
};
|
||||
@@ -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'}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"@tanstack/react-table": "^8.20.6",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"clsx": "^2.1.1",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"lodash": "^4.17.21",
|
||||
"lucide-react": "^0.474.0",
|
||||
"next": "15.1.4",
|
||||
@@ -29,6 +30,7 @@
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3",
|
||||
"@types/bcryptjs": "^2.4.6",
|
||||
"@types/jsonwebtoken": "^9.0.8",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
|
||||
Reference in New Issue
Block a user