Implement user authentication
Implement login functionality and user authentication logic.
This commit is contained in:
@@ -1,21 +1,32 @@
|
||||
import React, { useState } from "react";
|
||||
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ArrowRight, Mail, KeyRound, Eye, EyeOff } from "lucide-react";
|
||||
import { useToast } from "@/components/ui/use-toast";
|
||||
import { useAuth } from "@/contexts/AuthContext";
|
||||
|
||||
const Login = () => {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const {
|
||||
toast
|
||||
} = useToast();
|
||||
const { toast } = useToast();
|
||||
const navigate = useNavigate();
|
||||
const { signIn, user } = useAuth();
|
||||
|
||||
// 이미 로그인된 경우 메인 페이지로 리다이렉트
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
navigate("/");
|
||||
}
|
||||
}, [user, navigate]);
|
||||
|
||||
const handleLogin = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!email || !password) {
|
||||
toast({
|
||||
title: "입력 오류",
|
||||
@@ -24,19 +35,20 @@ const Login = () => {
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
|
||||
// 실제 로그인 로직은 추후 구현
|
||||
// 임시로 2초 후 로그인 성공으로 처리
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const { error } = await signIn(email, password);
|
||||
|
||||
if (!error) {
|
||||
navigate("/");
|
||||
}
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
toast({
|
||||
title: "로그인 성공",
|
||||
description: "환영합니다!"
|
||||
});
|
||||
navigate("/");
|
||||
}, 2000);
|
||||
}
|
||||
};
|
||||
|
||||
return <div className="min-h-screen flex flex-col items-center justify-center p-6 bg-neuro-background">
|
||||
<div className="w-full max-w-md">
|
||||
<div className="text-center mb-8">
|
||||
@@ -90,4 +102,5 @@ const Login = () => {
|
||||
</div>
|
||||
</div>;
|
||||
};
|
||||
|
||||
export default Login;
|
||||
|
||||
Reference in New Issue
Block a user