fixed bug lfwd

This commit is contained in:
Amirhossein Mahmoodi
2024-07-14 11:15:34 +03:30
parent 05220421d1
commit f063a4abd1

View File

@@ -1,12 +1,14 @@
"use client"; "use client";
import { GET_LOGIN_ROUTE } from "@/core/utils/routes"; import { GET_LOGIN_ROUTE } from "@/core/utils/routes";
import { useAuth } from "@/lib/contexts/auth";
import useRequest from "@/lib/hooks/useRequest"; import useRequest from "@/lib/hooks/useRequest";
import { Button, Stack, Typography, Zoom } from "@mui/material"; import { Button, Stack, Typography, Zoom } from "@mui/material";
import Link from "next/link"; import Link from "next/link";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
const Page = ({ searchParams }) => { const Page = ({ searchParams }) => {
const { getUser } = useAuth()
const { username } = searchParams; const { username } = searchParams;
const [login, setLogin] = useState(0); const [login, setLogin] = useState(0);
const request = useRequest(); const request = useRequest();
@@ -15,6 +17,7 @@ const Page = ({ searchParams }) => {
const login = async () => { const login = async () => {
try { try {
await request(`${GET_LOGIN_ROUTE}?username=${username}`); await request(`${GET_LOGIN_ROUTE}?username=${username}`);
getUser()
setLogin(1); setLogin(1);
} catch (error) { } catch (error) {
setLogin(2); setLogin(2);
@@ -28,6 +31,7 @@ const Page = ({ searchParams }) => {
setLogin(0); setLogin(0);
try { try {
await request(`${GET_LOGIN_ROUTE}?username=${username}`); await request(`${GET_LOGIN_ROUTE}?username=${username}`);
getUser()
setLogin(1); setLogin(1);
} catch (error) { } catch (error) {
setLogin(2); setLogin(2);
@@ -40,8 +44,8 @@ const Page = ({ searchParams }) => {
{login === 0 {login === 0
? "درحال دریافت مجوز برای ارتباط با سرور..." ? "درحال دریافت مجوز برای ارتباط با سرور..."
: login === 1 : login === 1
? "ارتباط با سرور برقرار شد." ? "ارتباط با سرور برقرار شد."
: "ارتباط با سرور برقرار نشد. مشکلی وجود دارد."} : "ارتباط با سرور برقرار نشد. مشکلی وجود دارد."}
</Typography> </Typography>
<Zoom in={login === 1}> <Zoom in={login === 1}>
<Button component={Link} href="/"> <Button component={Link} href="/">