✨ login integration
This commit is contained in:
parent
c8726eba73
commit
9f7482c002
@ -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 Link from 'next/link';
|
||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
import ComponentsAuthRegisterForm from '@/components/auth/components-auth-register-form';
|
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 Link from 'next/link';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
@ -30,14 +26,10 @@ const RegisterPage = (props: Props) => {
|
|||||||
<p className="text-base font-bold leading-normal text-white-dark">Enter your email and password to register</p>
|
<p className="text-base font-bold leading-normal text-white-dark">Enter your email and password to register</p>
|
||||||
</div>
|
</div>
|
||||||
<ComponentsAuthRegisterForm />
|
<ComponentsAuthRegisterForm />
|
||||||
<div className="relative my-7 text-center md:mb-9">
|
|
||||||
<span className="absolute inset-x-0 top-1/2 h-px w-full -translate-y-1/2 bg-white-light dark:bg-white-dark"></span>
|
|
||||||
<span className="relative bg-white px-2 font-bold uppercase text-white-dark dark:bg-dark dark:text-white-light">or</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="text-center dark:text-white">
|
<div className="text-center dark:text-white">
|
||||||
Already have an account ?
|
Already have an account ?
|
||||||
<Link href="/auth/boxed-signin" className="uppercase text-primary underline transition hover:text-black dark:hover:text-white">
|
<Link href="/login" className="uppercase text-primary underline transition hover:text-black dark:hover:text-white">
|
||||||
SIGN IN
|
SIGN IN
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,13 +2,36 @@
|
|||||||
import IconLockDots from '@/components/icon/icon-lock-dots';
|
import IconLockDots from '@/components/icon/icon-lock-dots';
|
||||||
import IconMail from '@/components/icon/icon-mail';
|
import IconMail from '@/components/icon/icon-mail';
|
||||||
import { useRouter } from 'next/navigation';
|
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 ComponentsAuthLoginForm = () => {
|
||||||
const router = useRouter();
|
const [email, setEmail] = useState("")
|
||||||
const submitForm = (e: any) => {
|
const [password, setPassword] = useState("")
|
||||||
e.preventDefault();
|
const [loading, setLoading] = useState(false)
|
||||||
router.push('/');
|
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 (
|
return (
|
||||||
@ -16,7 +39,7 @@ const ComponentsAuthLoginForm = () => {
|
|||||||
<div>
|
<div>
|
||||||
<label htmlFor="Email">Email</label>
|
<label htmlFor="Email">Email</label>
|
||||||
<div className="relative text-white-dark">
|
<div className="relative text-white-dark">
|
||||||
<input id="Email" type="email" placeholder="Enter Email" className="form-input ps-10 placeholder:text-white-dark" />
|
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="Enter Email" className="form-input ps-10 placeholder:text-white-dark" />
|
||||||
<span className="absolute start-4 top-1/2 -translate-y-1/2">
|
<span className="absolute start-4 top-1/2 -translate-y-1/2">
|
||||||
<IconMail fill={true} />
|
<IconMail fill={true} />
|
||||||
</span>
|
</span>
|
||||||
@ -25,14 +48,14 @@ const ComponentsAuthLoginForm = () => {
|
|||||||
<div>
|
<div>
|
||||||
<label htmlFor="Password">Password</label>
|
<label htmlFor="Password">Password</label>
|
||||||
<div className="relative text-white-dark">
|
<div className="relative text-white-dark">
|
||||||
<input id="Password" type="password" placeholder="Enter Password" className="form-input ps-10 placeholder:text-white-dark" />
|
<input type="password" value={password} onChange={(e) => setPassword(e.target.value)} required placeholder="Enter Password" className="form-input ps-10 placeholder:text-white-dark" />
|
||||||
<span className="absolute start-4 top-1/2 -translate-y-1/2">
|
<span className="absolute start-4 top-1/2 -translate-y-1/2">
|
||||||
<IconLockDots fill={true} />
|
<IconLockDots fill={true} />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" className="btn btn-gradient !mt-6 w-full border-0 uppercase shadow-[0_10px_20px_-10px_rgba(67,97,238,0.44)]">
|
<button type="submit" disabled={loading} className="btn btn-gradient !mt-6 w-full border-0 uppercase shadow-[0_10px_20px_-10px_rgba(67,97,238,0.44)]">
|
||||||
Sign in
|
{loading ? "Logging in..." : "Sign In"}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user