add auth and base functions and fixed bug

This commit is contained in:
Amirhossein Mahmoodi
2024-07-09 11:28:59 +03:30
parent 6288ac926c
commit 863bdaca95
23 changed files with 592 additions and 69 deletions

View File

@@ -1,11 +0,0 @@
import 'react-toastify/dist/ReactToastify.css';
const Layout = ({children}) => {
return (
<>
{children}
</>
)
}
export default Layout

View File

@@ -1,6 +1,28 @@
'use client'
import { Button } from "@mui/material"
import axios from "axios"
const Page = () => {
const handler = () => {
try {
axios.get('https://rms.witel.ir/test_login?username=witel', { withCredentials: true })
} catch (error) {
console.log(error);
}
}
const handler2 = () => {
try {
const res = axios.get('https://rms.witel.ir/webapi/user/get-permission', { withCredentials: true })
console.log(res);
} catch (error) {
console.log(error);
}
}
return (
<div>dashboard</div>
<>
<Button onClick={handler}>login</Button>
<Button onClick={handler2}>check</Button>
</>
)
}

View File

@@ -1,17 +1,19 @@
import {Box, Stack} from "@mui/material";
import { Box, Stack } from "@mui/material";
import HeaderWithLogo from "@/components/layouts/dashboard/headerWithLogo";
import HeaderWithSidebar from "@/components/layouts/dashboard/headerWithSidebar";
import 'react-toastify/dist/ReactToastify.css';
const Template = ({children}) => {
return (<Stack>
<HeaderWithLogo/>
<Box>
<HeaderWithSidebar>
{children}
</HeaderWithSidebar>
</Box>
</Stack>)
const Template = ({ children }) => {
return (
<Stack>
<HeaderWithLogo />
<Box>
<HeaderWithSidebar>
{children}
</HeaderWithSidebar>
</Box>
</Stack>
)
}
export default Template

View File

@@ -0,0 +1,14 @@
import WithAuthMiddleware from "@/core/middlewares/withAuth"
import { AuthProvider } from "@/lib/contexts/auth"
const Layout = ({ children }) => {
return (
<AuthProvider>
<WithAuthMiddleware>
{children}
</WithAuthMiddleware>
</AuthProvider>
)
}
export default Layout

View File

@@ -1,17 +1,17 @@
import {TableSettingProvider} from "@/lib/contexts/tableSetting";
import { TableSettingProvider } from "@/lib/contexts/tableSetting";
export const metadata = {
title: 'سامانه جامع راهداری',
}
export default function RootLayout({children}) {
export default function RootLayout({ children }) {
return (
<html lang="fa" dir={'rtl'}>
<body style={{height: '100vh'}}>
<TableSettingProvider>
{children}
</TableSettingProvider>
</body>
<body style={{ height: '100vh' }}>
<TableSettingProvider>
{children}
</TableSettingProvider>
</body>
</html>
)
}

51
src/app/lfwd/page.js Normal file
View File

@@ -0,0 +1,51 @@
'use client'
import { GET_LOGIN_ROUTE } from "@/core/utils/routes"
import useRequest from "@/lib/hooks/useRequest"
import { Button, Stack, Typography, Zoom } from "@mui/material"
import Link from "next/link"
import { useEffect, useState } from "react"
const Page = () => {
const [login, setLogin] = useState(0)
const request = useRequest()
useEffect(() => {
const login = async () => {
try {
const res = await request(`${GET_LOGIN_ROUTE}?username=witel`)
setLogin(1)
} catch (error) {
setLogin(2)
}
}
login()
}, [])
const retry = async () => {
setLogin(0)
try {
const res = await request(`${GET_LOGIN_ROUTE}?username=witel`)
setLogin(1)
} catch (error) {
setLogin(2)
}
}
return (
<Stack alignItems={'center'} justifyContent={'center'} sx={{ height: '100%' }} spacing={2}>
<Typography variant="h5">
{login === 0 ? 'درحال دریافت مجوز برای ارتباط با سرور...' : login === 1 ? 'ارتباط با سرور برقرار شد.' : 'ارتباط با سرور برقرار نشد. مشکلی وجود دارد.'}
</Typography>
<Zoom in={login === 1}>
<Button component={Link} href="/">ورود به سامانه</Button>
</Zoom>
<Zoom in={login === 2}>
<Button onClick={retry}>تلاش مجدد</Button>
</Zoom>
</Stack>
)
}
export default Page

View File

@@ -1,18 +1,18 @@
import cacheProviderRtl from "@/core/utils/cacheRtl";
import {CssBaseline, ThemeProvider} from "@mui/material";
import { CssBaseline, ThemeProvider } from "@mui/material";
import theme from "@/core/utils/theme";
import {AppRouterCacheProvider} from "@mui/material-nextjs/v14-appRouter";
import 'react-toastify/dist/ReactToastify.css';
import { AppRouterCacheProvider } from "@mui/material-nextjs/v14-appRouter";
import "^/global.scss";
import {ToastContainer} from "react-toastify";
import { ToastContainer } from "react-toastify";
const Template = ({children}) => {
const Template = ({ children }) => {
return (
<AppRouterCacheProvider CacheProvider={cacheProviderRtl} options={{enableCssLayer: true}}>
<AppRouterCacheProvider CacheProvider={cacheProviderRtl} options={{ enableCssLayer: true }}>
<ThemeProvider theme={theme}>
<CssBaseline/>
<CssBaseline />
{children}
<ToastContainer rtl containerId="filtering" closeButton={false}/>
<ToastContainer rtl containerId="filtering" closeButton={false} />
<ToastContainer rtl containerId="request_data" />
</ThemeProvider>
</AppRouterCacheProvider>
)