|
@@ -1,16 +1,25 @@
|
|
|
import { useState } from 'react';
|
|
import { useState } from 'react';
|
|
|
-import { Link, useNavigate } from 'react-router-dom';
|
|
|
|
|
|
|
+import { Link, useNavigate, useLocation } from 'react-router-dom';
|
|
|
import { useAuth } from '@picobaas/client/react';
|
|
import { useAuth } from '@picobaas/client/react';
|
|
|
import LoadingSpinner from '../components/LoadingSpinner';
|
|
import LoadingSpinner from '../components/LoadingSpinner';
|
|
|
|
|
|
|
|
|
|
+interface LocationState {
|
|
|
|
|
+ message?: string;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export default function LoginPage() {
|
|
export default function LoginPage() {
|
|
|
const navigate = useNavigate();
|
|
const navigate = useNavigate();
|
|
|
|
|
+ const location = useLocation();
|
|
|
const { login, isAuthenticated } = useAuth();
|
|
const { login, isAuthenticated } = useAuth();
|
|
|
const [email, setEmail] = useState('');
|
|
const [email, setEmail] = useState('');
|
|
|
const [password, setPassword] = useState('');
|
|
const [password, setPassword] = useState('');
|
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
|
|
|
|
|
+ // Get session expiry message from navigation state
|
|
|
|
|
+ const locationState = location.state as LocationState | null;
|
|
|
|
|
+ const sessionMessage = locationState?.message;
|
|
|
|
|
+
|
|
|
// Redirect if already authenticated
|
|
// Redirect if already authenticated
|
|
|
if (isAuthenticated) {
|
|
if (isAuthenticated) {
|
|
|
navigate('/dashboard', { replace: true });
|
|
navigate('/dashboard', { replace: true });
|
|
@@ -49,6 +58,11 @@ export default function LoginPage() {
|
|
|
|
|
|
|
|
<div className="card p-6">
|
|
<div className="card p-6">
|
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
|
|
|
+ {sessionMessage && (
|
|
|
|
|
+ <div className="p-3 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg text-amber-700 dark:text-amber-400 text-sm">
|
|
|
|
|
+ {sessionMessage}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
{error && (
|
|
{error && (
|
|
|
<div className="p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg text-red-700 dark:text-red-400 text-sm">
|
|
<div className="p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg text-red-700 dark:text-red-400 text-sm">
|
|
|
{error}
|
|
{error}
|