Skip to content

Commit 2dbcd91

Browse files
Change auth to per-page
1 parent 7f87369 commit 2dbcd91

File tree

6 files changed

+29
-58
lines changed

6 files changed

+29
-58
lines changed

workshop-ui/next.config.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ import type { NextConfig } from "next";
33
const nextConfig: NextConfig = {
44
output: 'standalone',
55
/* config options here */
6-
webpack: (
7-
config,
8-
{ buildId, dev, isServer, defaultLoaders, nextRuntime, webpack }
9-
) => {
10-
config.plugins.push(
11-
new webpack.IgnorePlugin({
12-
resourceRegExp: /middleware\.ts|instrumentation\.ts/,
13-
})
14-
);
15-
16-
// Important: return the modified config
17-
return config
18-
},
196
};
207

218
export default nextConfig;

workshop-ui/src/app/chat/[exercise]/page.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,15 @@ export default function Home() {
9898
const fetchExerciseMetadata = async () => {
9999
try {
100100
const response = await fetch(`/api/exercises/${exercise}`);
101+
if (response.status === 401) {
102+
// Wenn 401 Unauthorized, weiterleiten zur Login-Seite
103+
router.push('/login?from=/');
104+
throw new Error('Nicht autorisiert');
105+
}
101106
if (response.ok) {
102107
const metadata = await response.json();
103108
setExerciseTitle(metadata.title);
104-
109+
105110
// Add welcome message as first assistant message if it exists
106111
if (metadata.welcome_message && !welcomeMessageLoaded) {
107112
const welcomeMessage: MessageType = {
@@ -286,7 +291,7 @@ export default function Home() {
286291
</div>
287292
</div>
288293

289-
{/* System Prompt Modal */}
294+
{/* System Prompt Modal */}
290295
<Modal isOpen={isSystemPromptModalOpen} onClose={() => setIsSystemPromptModalOpen(false)} title="System Prompt">
291296
<SystemPrompt exerciseId={exercise} type="system-prompt" />
292297
</Modal>

workshop-ui/src/app/page.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import styles from './page.module.css';
33
import { getExercises } from '@/lib/exercise-file-manager';
44
import { trace } from '@opentelemetry/api';
55
import LogoutButton from '@/components/LogoutButton';
6+
import { getAppSession, validateAppSession } from '@/lib/session';
7+
import { redirect } from 'next/navigation';
8+
import { headers } from 'next/headers';
69

710
export default async function Home() {
811
const exercisesResult = await getExercises();
@@ -38,6 +41,14 @@ export default async function Home() {
3841
return '';
3942
}
4043
}
44+
45+
// redirect to login if not authenticated
46+
const isAuthenticated = await validateAppSession(await getAppSession());
47+
if (!isAuthenticated) {
48+
const headersList = await headers();
49+
const pathname = headersList.get('x-pathname') || '/';
50+
redirect('/login?from=' + encodeURIComponent(pathname));
51+
}
4152

4253
return (
4354
<>

workshop-ui/src/app/workshops/[id]/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export default function EditWorkshopPage() {
2929
setLoading(true);
3030
fetch(`/api/workshops/${id}`)
3131
.then(async res => {
32+
if (res.status === 401) {
33+
// Wenn 401 Unauthorized, weiterleiten zur Login-Seite
34+
router.push('/login?from=/');
35+
throw new Error('Nicht autorisiert');
36+
}
3237
if (!res.ok) throw new Error('Workshop nicht gefunden');
3338
return res.json();
3439
})

workshop-ui/src/app/workshops/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import styles from './page.module.css';
55
import WorkshopForm from '@/components/WorkshopForm';
66
import type { WorkshopInput } from '@/lib/workshop-schema';
77
import { Clipboard, ClipboardCheck, Pencil } from 'lucide-react';
8+
import { th } from 'zod/v4/locales';
89
interface Workshop {
910
id: number;
1011
title: string;
@@ -46,6 +47,11 @@ export default function WorkshopsPage() {
4647
setLoading(true);
4748
fetch('/api/workshops')
4849
.then(async res => {
50+
if (res.status === 401) {
51+
// Wenn 401 Unauthorized, weiterleiten zur Login-Seite
52+
router.push('/login?from=/');
53+
throw new Error('Nicht autorisiert');
54+
}
4955
if (!res.ok) throw new Error('Fehler beim Laden der Workshops');
5056
return res.json();
5157
})

workshop-ui/src/middleware.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)