Rebuild authentication page

Rebuild the authentication page.
This commit is contained in:
gpt-engineer-app[bot] 2025-03-10 08:37:22 +00:00
parent 4e4d446422
commit 746a8dbea0

View File

@ -2,7 +2,7 @@
import { useState } from 'react'; import { useState } from 'react';
import { Navigate } from 'react-router-dom'; import { Navigate } from 'react-router-dom';
import { useAuth } from '@/contexts/AuthContext'; import { useAuth } from '@/contexts/AuthContext';
import { ShieldCheck, Mail, Lock, User } from 'lucide-react'; import { ShieldCheck, Mail, Lock, User, Loader2 } from 'lucide-react';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input'; import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label'; import { Label } from '@/components/ui/label';
@ -15,8 +15,9 @@ const Auth = () => {
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const [fullName, setFullName] = useState(''); const [fullName, setFullName] = useState('');
const [authError, setAuthError] = useState<string | null>(null); const [authError, setAuthError] = useState<string | null>(null);
const [activeTab, setActiveTab] = useState('login');
// If user is already logged in, redirect to home page // If user is already logged in, redirect to dashboard
if (user) { if (user) {
return <Navigate to="/dashboard" />; return <Navigate to="/dashboard" />;
} }
@ -27,7 +28,8 @@ const Auth = () => {
try { try {
await signIn(email, password); await signIn(email, password);
} catch (error: any) { } catch (error: any) {
setAuthError(error.message); console.error('Sign in error:', error);
// Error is already handled by the toast in AuthContext
} }
}; };
@ -36,30 +38,38 @@ const Auth = () => {
setAuthError(null); setAuthError(null);
try { try {
await signUp(email, password, fullName); await signUp(email, password, fullName);
// Switch to login tab after successful signup
setActiveTab('login');
} catch (error: any) { } catch (error: any) {
setAuthError(error.message); console.error('Sign up error:', error);
// Error is already handled by the toast in AuthContext
} }
}; };
return ( return (
<div className="min-h-screen flex items-center justify-center bg-muted/30 px-4"> <div className="min-h-screen flex items-center justify-center bg-gradient-to-b from-muted/50 to-muted/30 px-4 py-8">
<div className="max-w-md w-full"> <div className="w-full max-w-md">
<div className="text-center mb-8"> <div className="text-center mb-8">
<div className="inline-flex mb-6 p-4 bg-primary/10 rounded-full"> <div className="inline-flex items-center justify-center mb-4 w-16 h-16 rounded-full bg-primary/10">
<ShieldCheck className="w-8 h-8 text-primary" /> <ShieldCheck className="w-8 h-8 text-primary" />
</div> </div>
<h1 className="text-3xl font-bold mb-2">SecuPolicy</h1> <h1 className="text-3xl font-bold mb-2">SecuPolicy</h1>
<p className="text-muted-foreground">Sign in to access your account</p> <p className="text-muted-foreground">Secure access to your account</p>
</div> </div>
<Tabs defaultValue="login" className="w-full"> <Tabs
defaultValue="login"
value={activeTab}
onValueChange={setActiveTab}
className="w-full"
>
<TabsList className="grid w-full grid-cols-2 mb-6"> <TabsList className="grid w-full grid-cols-2 mb-6">
<TabsTrigger value="login">Login</TabsTrigger> <TabsTrigger value="login">Sign In</TabsTrigger>
<TabsTrigger value="register">Register</TabsTrigger> <TabsTrigger value="register">Create Account</TabsTrigger>
</TabsList> </TabsList>
<TabsContent value="login"> <TabsContent value="login">
<Card> <Card className="border-2">
<CardHeader> <CardHeader>
<CardTitle>Welcome back</CardTitle> <CardTitle>Welcome back</CardTitle>
<CardDescription> <CardDescription>
@ -104,10 +114,17 @@ const Auth = () => {
<CardFooter> <CardFooter>
<Button <Button
type="submit" type="submit"
className="w-full rounded-full" className="w-full"
disabled={loading} disabled={loading}
> >
{loading ? 'Signing in...' : 'Sign In'} {loading ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Signing in...
</>
) : (
'Sign In'
)}
</Button> </Button>
</CardFooter> </CardFooter>
</form> </form>
@ -115,7 +132,7 @@ const Auth = () => {
</TabsContent> </TabsContent>
<TabsContent value="register"> <TabsContent value="register">
<Card> <Card className="border-2">
<CardHeader> <CardHeader>
<CardTitle>Create an account</CardTitle> <CardTitle>Create an account</CardTitle>
<CardDescription> <CardDescription>
@ -176,10 +193,17 @@ const Auth = () => {
<CardFooter> <CardFooter>
<Button <Button
type="submit" type="submit"
className="w-full rounded-full" className="w-full"
disabled={loading} disabled={loading}
> >
{loading ? 'Creating account...' : 'Create Account'} {loading ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Creating account...
</>
) : (
'Create Account'
)}
</Button> </Button>
</CardFooter> </CardFooter>
</form> </form>