✨ register integration
This commit is contained in:
parent
1519b2d0f1
commit
c3001d8b8f
@ -14,8 +14,8 @@ const ComponentsAuthLoginForm = () => {
|
|||||||
|
|
||||||
const submitForm = async (e: React.FormEvent) => {
|
const submitForm = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setLoading(true)
|
|
||||||
|
|
||||||
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
const res = await axios.post(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/login`, {
|
const res = await axios.post(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/login`, {
|
||||||
email,
|
email,
|
||||||
@ -32,7 +32,7 @@ const ComponentsAuthLoginForm = () => {
|
|||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="space-y-5 dark:text-white" onSubmit={submitForm}>
|
<form className="space-y-5 dark:text-white" onSubmit={submitForm}>
|
||||||
|
@ -2,15 +2,38 @@
|
|||||||
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 IconUser from '@/components/icon/icon-user';
|
import IconUser from '@/components/icon/icon-user';
|
||||||
|
import axios from 'axios';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useState } from "react";
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
|
||||||
const ComponentsAuthRegisterForm = () => {
|
const ComponentsAuthRegisterForm = () => {
|
||||||
const router = useRouter();
|
const [email, setEmail] = useState("")
|
||||||
|
const [password, setPassword] = useState("")
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
const submitForm = (e: any) => {
|
const submitForm = async(e: any) => {
|
||||||
e.preventDefault();
|
e.preventDefault()
|
||||||
router.push('/');
|
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const res = await axios.post(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/register`, {
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
})
|
||||||
|
|
||||||
|
localStorage.setItem("token", res.data.token)
|
||||||
|
|
||||||
|
toast.success("Register successful!")
|
||||||
|
router.push("/")
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error("Register error:", err)
|
||||||
|
toast.error(err.response?.data?.error || "Something went wrong")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<form className="space-y-5 dark:text-white" onSubmit={submitForm}>
|
<form className="space-y-5 dark:text-white" onSubmit={submitForm}>
|
||||||
@ -26,7 +49,7 @@ const ComponentsAuthRegisterForm = () => {
|
|||||||
<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 value={email} onChange={(e) => setEmail(e.target.value)} type="email" 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>
|
||||||
@ -35,14 +58,14 @@ const ComponentsAuthRegisterForm = () => {
|
|||||||
<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 value={password} onChange={(e) => setPassword(e.target.value)} type="password" 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 Up
|
{loading ? "Creating account..." : "Register"}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user