diff --git a/ui/app/api/logout/route.ts b/ui/app/api/logout/route.ts
index 3721a6bff8..5faf5a8c84 100644
--- a/ui/app/api/logout/route.ts
+++ b/ui/app/api/logout/route.ts
@@ -1,7 +1,6 @@
import { cookies } from 'next/headers';
-import { NextResponse } from 'next/server';
export async function POST(req: Request) {
cookies().delete('auth');
- return NextResponse.redirect(new URL('/login', req.url));
+ return new Response('');
}
diff --git a/ui/app/login/page.tsx b/ui/app/login/page.tsx
index e05b782905..d158978aab 100644
--- a/ui/app/login/page.tsx
+++ b/ui/app/login/page.tsx
@@ -1,14 +1,30 @@
'use client';
import Image from 'next/image';
+import { useRouter, useSearchParams } from 'next/navigation';
import { useState } from 'react';
import { Button } from '@/lib/Button';
import { Layout, LayoutMain } from '@/lib/Layout';
import { TextField } from '@/lib/TextField';
-export default function Password() {
+export default function Login() {
+ const router = useRouter();
+ const searchParams = useSearchParams();
const [pass, setPass] = useState('');
- const [error, setError] = useState('');
+ const [error, setError] = useState(() =>
+ searchParams.has('reject') ? 'Authentication failed, please login' : ''
+ );
+ const login = () => {
+ fetch('/api/login', {
+ method: 'POST',
+ body: JSON.stringify({ password: pass }),
+ })
+ .then((res) => res.json())
+ .then((res) => {
+ if (res.error) setError(res.error);
+ else router.push('/');
+ });
+ };
return (
@@ -32,21 +48,13 @@ export default function Password() {
onChange={(e: React.ChangeEvent) =>
setPass(e.target.value)
}
- />
-
+ />
+
);
diff --git a/ui/app/page.tsx b/ui/app/page.tsx
index 13f1ebb374..d89f981887 100644
--- a/ui/app/page.tsx
+++ b/ui/app/page.tsx
@@ -1,4 +1,3 @@
-import Logout from '@/components/Logout';
import SidebarComponent from '@/components/SidebarComponent';
import { Header } from '@/lib/Header';
import { Layout, LayoutMain } from '@/lib/Layout';
@@ -6,10 +5,9 @@ import { cookies } from 'next/headers';
export default function Home() {
return (
- }>
+ }>
- {cookies().get('auth') && }
);
diff --git a/ui/components/Logout.tsx b/ui/components/Logout.tsx
index 72975b8fc3..21c8e8267a 100644
--- a/ui/components/Logout.tsx
+++ b/ui/components/Logout.tsx
@@ -3,7 +3,13 @@ import { Button } from '@/lib/Button';
export default function Logout() {
return (
-