fix(nav): fix exam flow navigation

chore(zustand): refactor auth code for zustand store
This commit is contained in:
shafin-r
2025-09-09 20:45:30 +06:00
parent c3ead879ad
commit 108d34988d
11 changed files with 172 additions and 126 deletions

View File

@ -6,7 +6,6 @@ import { useRouter } from "next/navigation";
import Image from "next/image";
import BackgroundWrapper from "@/components/BackgroundWrapper";
import FormField from "@/components/FormField";
import { login } from "@/lib/auth";
import DestructibleAlert from "@/components/DestructibleAlert";
import { LoginForm } from "@/types/auth";
import { CircleAlert } from "lucide-react";
@ -14,7 +13,7 @@ import { useAuthStore } from "@/stores/authStore";
const LoginPage = () => {
const router = useRouter();
const { setToken } = useAuthStore();
const { login } = useAuthStore();
const [form, setForm] = useState<LoginForm>({
identifier: "",
@ -28,7 +27,7 @@ const LoginPage = () => {
try {
setIsLoading(true);
setError(null);
await login(form, setToken);
await login(form);
router.replace("/home");
} catch (err: unknown) {
console.error(err);

View File

@ -4,8 +4,6 @@ import { useState } from "react";
import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { register } from "@/lib/auth";
import BackgroundWrapper from "@/components/BackgroundWrapper";
import FormField from "@/components/FormField";
import DestructibleAlert from "@/components/DestructibleAlert";
@ -27,7 +25,7 @@ interface CustomError extends Error {
}
export default function RegisterPage() {
const { setToken } = useAuthStore();
const { register } = useAuthStore();
const router = useRouter();
const [form, setForm] = useState<RegisterForm>({
full_name: "",
@ -87,7 +85,7 @@ export default function RegisterPage() {
}
try {
await register(form, setToken);
await register(form);
router.replace("/login");
} catch (err: unknown) {
setError(formatError(err));