mirror of
http://88.130.71.182:3000/BlitTech/badoHair_fe.git
synced 2026-06-13 08:58:31 +00:00
changes after second dev test
fixed full name issue, refresh issue on reservation and user/admin login issue
This commit is contained in:
@@ -15,7 +15,7 @@ type Mode = "login" | "register" | "forgot";
|
||||
|
||||
export default function Auth() {
|
||||
const { t } = useLanguage();
|
||||
const { login, register, user } = useAuth();
|
||||
const { login, register, logout, user } = useAuth();
|
||||
const router = useRouter();
|
||||
const [mode, setMode] = useState<Mode>("login");
|
||||
const [email, setEmail] = useState("");
|
||||
@@ -24,9 +24,7 @@ export default function Auth() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
router.replace(user.role === "admin" ? "/admin" : "/");
|
||||
}
|
||||
if (user) router.replace("/");
|
||||
}, [user, router]);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
@@ -35,13 +33,18 @@ export default function Auth() {
|
||||
try {
|
||||
if (mode === "login") {
|
||||
const profile = await login(email, password);
|
||||
if (profile.role === "admin") {
|
||||
logout();
|
||||
toast.error(t("auth.admin_not_allowed"));
|
||||
return;
|
||||
}
|
||||
toast.success(t("auth.login_success"));
|
||||
router.push(profile.role === "admin" ? "/admin" : "/");
|
||||
router.push("/");
|
||||
} else if (mode === "register") {
|
||||
const profile = await register(email, password, name);
|
||||
if (profile) {
|
||||
toast.success(t("auth.register_success"));
|
||||
router.push(profile.role === "admin" ? "/admin" : "/");
|
||||
router.push("/");
|
||||
} else {
|
||||
toast.success(t("auth.confirm_email"));
|
||||
router.push("/connexion");
|
||||
|
||||
Reference in New Issue
Block a user