From 9f7482c0029d87b4d29593f0f550a3936c4a6200 Mon Sep 17 00:00:00 2001 From: sam Date: Wed, 26 Feb 2025 17:36:44 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20login=20integration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(auth)/login/page.tsx | 5 --- app/(auth)/register/page.tsx | 10 +---- .../auth/components-auth-login-form.tsx | 41 +++++++++++++++---- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx index b3dca05..d7d6ef1 100644 --- a/app/(auth)/login/page.tsx +++ b/app/(auth)/login/page.tsx @@ -1,8 +1,3 @@ -import IconFacebookCircle from '@/components/icon/icon-facebook-circle'; -import IconGoogle from '@/components/icon/icon-google'; -import IconInstagram from '@/components/icon/icon-instagram'; -import IconTwitter from '@/components/icon/icon-twitter'; - import Link from 'next/link'; import { Metadata } from 'next'; import React from 'react'; diff --git a/app/(auth)/register/page.tsx b/app/(auth)/register/page.tsx index 3bb5cf6..5b3a7b1 100644 --- a/app/(auth)/register/page.tsx +++ b/app/(auth)/register/page.tsx @@ -1,8 +1,4 @@ import ComponentsAuthRegisterForm from '@/components/auth/components-auth-register-form'; -import IconFacebookCircle from '@/components/icon/icon-facebook-circle'; -import IconGoogle from '@/components/icon/icon-google'; -import IconInstagram from '@/components/icon/icon-instagram'; -import IconTwitter from '@/components/icon/icon-twitter'; import Link from 'next/link'; import React from 'react'; @@ -30,14 +26,10 @@ const RegisterPage = (props: Props) => {

Enter your email and password to register

-
- - or -
Already have an account ?  - + SIGN IN
diff --git a/components/auth/components-auth-login-form.tsx b/components/auth/components-auth-login-form.tsx index 1a804d6..ac1f086 100644 --- a/components/auth/components-auth-login-form.tsx +++ b/components/auth/components-auth-login-form.tsx @@ -2,13 +2,36 @@ import IconLockDots from '@/components/icon/icon-lock-dots'; import IconMail from '@/components/icon/icon-mail'; import { useRouter } from 'next/navigation'; -import React from 'react'; +import { useState } from "react"; +import axios from "axios"; +import toast from 'react-hot-toast'; const ComponentsAuthLoginForm = () => { - const router = useRouter(); - const submitForm = (e: any) => { - e.preventDefault(); - router.push('/'); + const [email, setEmail] = useState("") + const [password, setPassword] = useState("") + const [loading, setLoading] = useState(false) + const router = useRouter() + + const submitForm = async (e: React.FormEvent) => { + e.preventDefault() + setLoading(true) + + try { + const res = await axios.post(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/login`, { + email, + password, + }) + + localStorage.setItem("token", res.data.token) + + toast.success("Login successful!") + router.push("/") + } catch (err: any) { + console.error("Login error:", err) + toast.error(err.response?.data?.error || "Invalid credentials") + } finally { + setLoading(false) + } }; return ( @@ -16,7 +39,7 @@ const ComponentsAuthLoginForm = () => {
- + setEmail(e.target.value)} placeholder="Enter Email" className="form-input ps-10 placeholder:text-white-dark" /> @@ -25,14 +48,14 @@ const ComponentsAuthLoginForm = () => {
- + setPassword(e.target.value)} required placeholder="Enter Password" className="form-input ps-10 placeholder:text-white-dark" />
- );