From fd323d8a3cabe9d4129cb7c58aada3242e8adad5 Mon Sep 17 00:00:00 2001 From: Prakash Maity Date: Wed, 7 Aug 2024 23:46:44 +0530 Subject: [PATCH] fix(commentsAdded) --- src/app/(auth)/login/page.tsx | 9 +++++++++ src/app/(dashboard)/products/page.tsx | 1 + src/services/axios/axiosInstance.ts | 1 + 3 files changed, 11 insertions(+) diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx index 32b356d..cc79b45 100644 --- a/src/app/(auth)/login/page.tsx +++ b/src/app/(auth)/login/page.tsx @@ -20,6 +20,7 @@ import { routes } from "constant/route.constant"; import { grey } from "@mui/material/colors"; import Snackbar, { SnackbarCloseReason } from '@mui/material/Snackbar'; +// zod resolver are using for form validation const loginSchema = z.object({ username: z.string(), password: z.string().min(6, { message: "Password is too short" }) @@ -31,6 +32,8 @@ type LoginFormValues = z.infer; export default function LoginPage() { const [loader, setLoader] = useState(false); const router = useRouter(); + + // here hooks form is used for form validation and form submission const { handleSubmit, formState: { errors }, @@ -40,12 +43,17 @@ export default function LoginPage() { }); const [error, setError] = useState(""); const dispatch = useDispatch(); + + // onsubmit function is used for form submission const onSubmit = async (data: LoginFormValues) => { try { setLoader(true); const response = await loginApi(data); + localStorage.setItem("token", response.token); localStorage.setItem("refreshToken", response.refreshToken); + + dispatch( setAuthTokens({ token: response.token, @@ -72,6 +80,7 @@ export default function LoginPage() { }; return (
+ {/* Snackbar is used for showing error message */} { + // need to api call for all products const data = await homeServices.getProducts(); return ( diff --git a/src/services/axios/axiosInstance.ts b/src/services/axios/axiosInstance.ts index 540a886..258760b 100644 --- a/src/services/axios/axiosInstance.ts +++ b/src/services/axios/axiosInstance.ts @@ -2,6 +2,7 @@ import axios from 'axios'; import { routes } from 'constant/route.constant'; +// we are useing axios for api calls and we are using axios instance for api calls. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using interceptors for adding token in headers and for refreshing token. we are using axios instance for api calls because we are using interceptors in axios instance. we are using intercept const axiosInstance = axios.create({ baseURL: process.env.NEXT_PUBLIC_API_URL, headers: {