Fix login button — useRef for input, window.location redirect. Add logout to settings.
This commit is contained in:
+12
-24
@@ -1,15 +1,14 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState, useRef } from 'react';
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
const [password, setPassword] = useState('');
|
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const router = useRouter();
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
async function handleLogin() {
|
async function handleLogin() {
|
||||||
|
const password = inputRef.current?.value || '';
|
||||||
if (!password || loading) return;
|
if (!password || loading) return;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError('');
|
setError('');
|
||||||
@@ -21,39 +20,31 @@ export default function LoginPage() {
|
|||||||
body: JSON.stringify({ password }),
|
body: JSON.stringify({ password }),
|
||||||
});
|
});
|
||||||
if (!res.ok) throw new Error('Invalid password');
|
if (!res.ok) throw new Error('Invalid password');
|
||||||
router.push('/');
|
window.location.href = '/';
|
||||||
router.refresh();
|
|
||||||
} catch {
|
} catch {
|
||||||
setError('Invalid password');
|
setError('Invalid password');
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleKeyDown(e: React.KeyboardEvent) {
|
|
||||||
if (e.key === 'Enter') handleLogin();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div style={{
|
||||||
style={{
|
|
||||||
minHeight: '100dvh',
|
minHeight: '100dvh',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
padding: '16px',
|
padding: '16px',
|
||||||
background: '#faf9f6',
|
background: '#faf9f6',
|
||||||
}}
|
fontFamily: 'system-ui, sans-serif',
|
||||||
>
|
}}>
|
||||||
<div
|
<div style={{
|
||||||
style={{
|
|
||||||
width: '100%',
|
width: '100%',
|
||||||
maxWidth: '360px',
|
maxWidth: '360px',
|
||||||
background: '#f0ede6',
|
background: '#f0ede6',
|
||||||
border: '1px solid #dddad2',
|
border: '1px solid #dddad2',
|
||||||
borderRadius: '16px',
|
borderRadius: '16px',
|
||||||
padding: '32px',
|
padding: '32px',
|
||||||
}}
|
}}>
|
||||||
>
|
|
||||||
<div style={{ textAlign: 'center', marginBottom: '32px' }}>
|
<div style={{ textAlign: 'center', marginBottom: '32px' }}>
|
||||||
<div style={{ fontSize: '22px', fontWeight: 500, color: '#1a1a18', marginBottom: '4px' }}>
|
<div style={{ fontSize: '22px', fontWeight: 500, color: '#1a1a18', marginBottom: '4px' }}>
|
||||||
Aaron AI
|
Aaron AI
|
||||||
@@ -64,13 +55,12 @@ export default function LoginPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
|
ref={inputRef}
|
||||||
type="password"
|
type="password"
|
||||||
value={password}
|
|
||||||
onChange={e => setPassword(e.target.value)}
|
|
||||||
onKeyDown={handleKeyDown}
|
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
autoFocus
|
autoFocus
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
|
onKeyDown={e => e.key === 'Enter' && handleLogin()}
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
background: '#faf9f6',
|
background: '#faf9f6',
|
||||||
@@ -94,7 +84,6 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={handleLogin}
|
onClick={handleLogin}
|
||||||
disabled={loading}
|
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
background: '#2d5a3d',
|
background: '#2d5a3d',
|
||||||
@@ -103,8 +92,7 @@ export default function LoginPage() {
|
|||||||
borderRadius: '10px',
|
borderRadius: '10px',
|
||||||
padding: '12px',
|
padding: '12px',
|
||||||
fontSize: '15px',
|
fontSize: '15px',
|
||||||
cursor: loading ? 'not-allowed' : 'pointer',
|
cursor: 'pointer',
|
||||||
opacity: loading ? 0.5 : 1,
|
|
||||||
display: 'block',
|
display: 'block',
|
||||||
boxSizing: 'border-box',
|
boxSizing: 'border-box',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useStore } from '@/lib/store';
|
import { useStore } from '@/lib/store';
|
||||||
import { api } from '@/lib/api';
|
import { api, auth } from '@/lib/api';
|
||||||
import type { Status } from '@/lib/api';
|
import type { Status } from '@/lib/api';
|
||||||
|
|
||||||
export default function SettingsPanel() {
|
export default function SettingsPanel() {
|
||||||
@@ -50,6 +50,11 @@ export default function SettingsPanel() {
|
|||||||
a.click();
|
a.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function logout() {
|
||||||
|
await auth.logout();
|
||||||
|
window.location.href = '/login';
|
||||||
|
}
|
||||||
|
|
||||||
async function clearAll() {
|
async function clearAll() {
|
||||||
if (!confirm('Delete all conversations permanently?')) return;
|
if (!confirm('Delete all conversations permanently?')) return;
|
||||||
await api.clearAllConversations();
|
await api.clearAllConversations();
|
||||||
|
|||||||
Reference in New Issue
Block a user