fix(commentsAdded)
This commit is contained in:
parent
5076a5b4b0
commit
fd323d8a3c
@ -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}
|
||||||
|
@ -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>
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user