Browse Source

fix(commentsAdded)

master
Prakash Maity 6 months ago
parent
commit
fd323d8a3c
3 changed files with 11 additions and 0 deletions
  1. +9
    -0
      src/app/(auth)/login/page.tsx
  2. +1
    -0
      src/app/(dashboard)/products/page.tsx
  3. +1
    -0
      src/services/axios/axiosInstance.ts

+ 9
- 0
src/app/(auth)/login/page.tsx View File

@ -20,6 +20,7 @@ import { routes } from "constant/route.constant";
import { grey } from "@mui/material/colors"; import { grey } from "@mui/material/colors";
import Snackbar, { SnackbarCloseReason } from '@mui/material/Snackbar'; import Snackbar, { SnackbarCloseReason } from '@mui/material/Snackbar';
// zod resolver are using for form validation
const loginSchema = z.object({ const loginSchema = z.object({
username: z.string(), username: z.string(),
password: z.string().min(6, { message: "Password is too short" }) password: z.string().min(6, { message: "Password is too short" })
@ -31,6 +32,8 @@ type LoginFormValues = z.infer<typeof loginSchema>;
export default function LoginPage() { export default function LoginPage() {
const [loader, setLoader] = useState(false); const [loader, setLoader] = useState(false);
const router = useRouter(); const router = useRouter();
// here hooks form is used for form validation and form submission
const { const {
handleSubmit, handleSubmit,
formState: { errors }, formState: { errors },
@ -40,12 +43,17 @@ export default function LoginPage() {
}); });
const [error, setError] = useState(""); const [error, setError] = useState("");
const dispatch = useDispatch(); const dispatch = useDispatch();
// onsubmit function is used for form submission
const onSubmit = async (data: LoginFormValues) => { const onSubmit = async (data: LoginFormValues) => {
try { try {
setLoader(true); setLoader(true);
const response = await loginApi(data); const response = await loginApi(data);
localStorage.setItem("token", response.token); localStorage.setItem("token", response.token);
localStorage.setItem("refreshToken", response.refreshToken); localStorage.setItem("refreshToken", response.refreshToken);
dispatch( dispatch(
setAuthTokens({ setAuthTokens({
token: response.token, token: response.token,
@ -72,6 +80,7 @@ export default function LoginPage() {
}; };
return ( return (
<main className={styles.loginPage}> <main className={styles.loginPage}>
{/* Snackbar is used for showing error message */}
<Snackbar <Snackbar
open={error ? true : false} open={error ? true : false}
autoHideDuration={3000} autoHideDuration={3000}


+ 1
- 0
src/app/(dashboard)/products/page.tsx View File

@ -7,6 +7,7 @@ import TitleHeader from "@/components/titleHeader/titleHeader";
import homeServices from "@/services/api/productsApi"; import homeServices from "@/services/api/productsApi";
const HomePage = async () => { const HomePage = async () => {
// need to api call for all products
const data = await homeServices.getProducts(); const data = await homeServices.getProducts();
return ( return (
<Box> <Box>


+ 1
- 0
src/services/axios/axiosInstance.ts View File

@ -2,6 +2,7 @@
import axios from 'axios'; import axios from 'axios';
import { routes } from 'constant/route.constant'; 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({ const axiosInstance = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL, baseURL: process.env.NEXT_PUBLIC_API_URL,
headers: { headers: {


Loading…
Cancel
Save