- {!isSubmitted ? (
-
) : (
-
-
-
-
-
-
이메일이 전송되었습니다
-
- {email}로 비밀번호 재설정 링크를 보냈습니다. 이메일을 확인해주세요.
-
-
-
diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx
index 1f88c36..ae3332a 100644
--- a/src/pages/Login.tsx
+++ b/src/pages/Login.tsx
@@ -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
@@ -90,4 +102,5 @@ const Login = () => {
;
};
+
export default Login;
diff --git a/src/pages/Register.tsx b/src/pages/Register.tsx
index 9d363b6..f090762 100644
--- a/src/pages/Register.tsx
+++ b/src/pages/Register.tsx
@@ -1,11 +1,12 @@
-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, User, Eye, EyeOff } from "lucide-react";
import { useToast } from "@/components/ui/use-toast";
+import { useAuth } from "@/contexts/AuthContext";
const Register = () => {
const [username, setUsername] = useState("");
@@ -16,6 +17,14 @@ const Register = () => {
const [isLoading, setIsLoading] = useState(false);
const { toast } = useToast();
const navigate = useNavigate();
+ const { signUp, user } = useAuth();
+
+ // 이미 로그인된 경우 메인 페이지로 리다이렉트
+ useEffect(() => {
+ if (user) {
+ navigate("/");
+ }
+ }, [user, navigate]);
const handleRegister = async (e: React.FormEvent) => {
e.preventDefault();
@@ -40,16 +49,15 @@ const Register = () => {
setIsLoading(true);
- // 실제 회원가입 로직은 추후 구현
- // 임시로 2초 후 회원가입 성공으로 처리
- setTimeout(() => {
+ try {
+ const { error, user } = await signUp(email, password, username);
+
+ if (!error && user) {
+ navigate("/login");
+ }
+ } finally {
setIsLoading(false);
- toast({
- title: "회원가입 성공",
- description: "로그인 페이지로 이동합니다.",
- });
- navigate("/login");
- }, 2000);
+ }
};
return (
diff --git a/src/pages/Settings.tsx b/src/pages/Settings.tsx
index 1955b91..24e608a 100644
--- a/src/pages/Settings.tsx
+++ b/src/pages/Settings.tsx
@@ -5,6 +5,7 @@ import NavBar from '@/components/NavBar';
import SyncSettings from '@/components/SyncSettings';
import { User, CreditCard, Bell, Lock, HelpCircle, LogOut, ChevronRight } from 'lucide-react';
import { cn } from '@/lib/utils';
+import { useAuth } from '@/contexts/AuthContext';
const SettingsOption = ({
icon: Icon,
@@ -35,6 +36,13 @@ const SettingsOption = ({
const Settings = () => {
const navigate = useNavigate();
+ const { user, signOut } = useAuth();
+
+ const handleLogout = async () => {
+ await signOut();
+ navigate('/login');
+ };
+
return
{/* Header */}
@@ -47,8 +55,12 @@ const Settings = () => {
-
홍길동
-
honggildong@example.com
+
+ {user ? user.user_metadata?.username || '사용자' : '로그인 필요'}
+
+
+ {user ? user.email : '계정에 로그인하세요'}
+
@@ -74,7 +86,12 @@ const Settings = () => {
-
+ navigate('/login')}
+ />