fix: guest route
This commit is contained in:
parent
c01db516b1
commit
1cd8adc1e2
@ -1,16 +1,13 @@
|
|||||||
// Type Imports
|
// Type Imports
|
||||||
import type { ChildrenType } from '@core/types'
|
import type { ChildrenType } from '@core/types'
|
||||||
import type { Locale } from '@configs/i18n'
|
|
||||||
|
|
||||||
// HOC Imports
|
// HOC Imports
|
||||||
import GuestOnlyRoute from '@/hocs/GuestOnlyRoute'
|
import GuestOnlyRoute from '@/hocs/GuestOnlyRoute'
|
||||||
|
|
||||||
const Layout = async (props: ChildrenType & { params: Promise<{ lang: Locale }> }) => {
|
const Layout = async (props: ChildrenType) => {
|
||||||
const params = await props.params
|
|
||||||
|
|
||||||
const { children } = props
|
const { children } = props
|
||||||
|
|
||||||
return <GuestOnlyRoute lang={params.lang}>{children}</GuestOnlyRoute>
|
return <GuestOnlyRoute>{children}</GuestOnlyRoute>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Layout
|
export default Layout
|
||||||
|
|||||||
@ -4,8 +4,6 @@
|
|||||||
import Grid from '@mui/material/Grid2'
|
import Grid from '@mui/material/Grid2'
|
||||||
|
|
||||||
// Component Imports
|
// Component Imports
|
||||||
import DistributedBarChartOrder from '@views/dashboards/crm/DistributedBarChartOrder'
|
|
||||||
import EarningReportsWithTabs from '@views/dashboards/crm/EarningReportsWithTabs'
|
|
||||||
|
|
||||||
// Server Action Imports
|
// Server Action Imports
|
||||||
import Loading from '../../../../../../components/layout/shared/Loading'
|
import Loading from '../../../../../../components/layout/shared/Loading'
|
||||||
|
|||||||
@ -91,7 +91,7 @@ const VerticalMenu = ({ dictionary, scrollMenu }: Props) => {
|
|||||||
<MenuItem href={`/${locale}/dashboards/daily-report`}>{dictionary['navigation'].dailyReport}</MenuItem>
|
<MenuItem href={`/${locale}/dashboards/daily-report`}>{dictionary['navigation'].dailyReport}</MenuItem>
|
||||||
</SubMenu>
|
</SubMenu>
|
||||||
<MenuSection label={dictionary['navigation'].appsPages}>
|
<MenuSection label={dictionary['navigation'].appsPages}>
|
||||||
<SubMenu label={dictionary['navigation'].eCommerce} icon={<i className='tabler-salad' />}>
|
<SubMenu label={dictionary['navigation'].inventory} icon={<i className='tabler-salad' />}>
|
||||||
{/* <MenuItem href={`/${locale}/apps/ecommerce/dashboard`}>{dictionary['navigation'].dashboard}</MenuItem> */}
|
{/* <MenuItem href={`/${locale}/apps/ecommerce/dashboard`}>{dictionary['navigation'].dashboard}</MenuItem> */}
|
||||||
<SubMenu label={dictionary['navigation'].products}>
|
<SubMenu label={dictionary['navigation'].products}>
|
||||||
<MenuItem href={`/${locale}/apps/ecommerce/products/list`}>{dictionary['navigation'].list}</MenuItem>
|
<MenuItem href={`/${locale}/apps/ecommerce/products/list`}>{dictionary['navigation'].list}</MenuItem>
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"navigation": {
|
"navigation": {
|
||||||
"dashboards": "لوحات القيادة",
|
"dashboards": "لوحات القيادة",
|
||||||
"analytics": "تحليلات",
|
"analytics": "تحليلات",
|
||||||
"eCommerce": "تجزئة الكترونية",
|
"inventory": "تجزئة الكترونية",
|
||||||
"stock": "المخزون",
|
"stock": "المخزون",
|
||||||
"academy": "أكاديمية",
|
"academy": "أكاديمية",
|
||||||
"logistics": "اللوجستية",
|
"logistics": "اللوجستية",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"navigation": {
|
"navigation": {
|
||||||
"dashboards": "Dashboards",
|
"dashboards": "Dashboards",
|
||||||
"analytics": "Analytics",
|
"analytics": "Analytics",
|
||||||
"eCommerce": "Inventory",
|
"inventory": "Inventory",
|
||||||
"stock": "Stock",
|
"stock": "Stock",
|
||||||
"academy": "Academy",
|
"academy": "Academy",
|
||||||
"logistics": "Logistics",
|
"logistics": "Logistics",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"navigation": {
|
"navigation": {
|
||||||
"dashboards": "Tableaux de bord",
|
"dashboards": "Tableaux de bord",
|
||||||
"analytics": "Analytique",
|
"analytics": "Analytique",
|
||||||
"eCommerce": "Inventaire",
|
"inventory": "Inventaire",
|
||||||
"stock": "Stock",
|
"stock": "Stock",
|
||||||
"academy": "Académie",
|
"academy": "Académie",
|
||||||
"logistics": "Logistique",
|
"logistics": "Logistique",
|
||||||
|
|||||||
@ -1,23 +1,34 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
// Next Imports
|
// Next Imports
|
||||||
|
|
||||||
// Type Imports
|
// Type Imports
|
||||||
import type { Locale } from '@configs/i18n'
|
|
||||||
import type { ChildrenType } from '@core/types'
|
import type { ChildrenType } from '@core/types'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
import { useAuth } from '../contexts/authContext'
|
||||||
|
import Loading from '../components/layout/shared/Loading'
|
||||||
|
|
||||||
// Config Imports
|
// Config Imports
|
||||||
|
|
||||||
// Util Imports
|
// Util Imports
|
||||||
|
|
||||||
const GuestOnlyRoute = async ({ children, lang }: ChildrenType & { lang: Locale }) => {
|
const GuestOnlyRoute = ({ children }: ChildrenType) => {
|
||||||
// const session = await getServerSession()
|
const router = useRouter()
|
||||||
|
|
||||||
// if (session) {
|
const { isAuthenticated, currentUser } = useAuth()
|
||||||
// redirect(getLocalizedUrl(themeConfig.homePageUrl, lang))
|
|
||||||
// }
|
|
||||||
|
|
||||||
console.log(lang)
|
useEffect(() => {
|
||||||
|
if (!isAuthenticated) return
|
||||||
|
|
||||||
return <>{children}</>
|
if (currentUser?.role === 'admin') {
|
||||||
|
router.push('/dashboards/overview')
|
||||||
|
} else {
|
||||||
|
router.push('/sa/organizations/list')
|
||||||
|
}
|
||||||
|
}, [isAuthenticated])
|
||||||
|
|
||||||
|
return <>{isAuthenticated ? <Loading /> : children}</>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default GuestOnlyRoute
|
export default GuestOnlyRoute
|
||||||
|
|||||||
@ -29,9 +29,9 @@ api.interceptors.response.use(
|
|||||||
response => response,
|
response => response,
|
||||||
error => {
|
error => {
|
||||||
const status = error.response?.status
|
const status = error.response?.status
|
||||||
|
const currentPath = window.location.pathname
|
||||||
|
|
||||||
if (status === 401) {
|
if (status === 401 && !currentPath.endsWith('/login')) {
|
||||||
console.warn('Unauthorized. Redirecting to login...')
|
|
||||||
window.location.href = '/login'
|
window.location.href = '/login'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,3 +46,4 @@ api.interceptors.response.use(
|
|||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,7 @@ import { useSettings } from '@core/hooks/useSettings'
|
|||||||
import { getLocalizedUrl } from '@/utils/i18n'
|
import { getLocalizedUrl } from '@/utils/i18n'
|
||||||
import { useAuthMutation } from '../services/mutations/auth'
|
import { useAuthMutation } from '../services/mutations/auth'
|
||||||
import { CircularProgress } from '@mui/material'
|
import { CircularProgress } from '@mui/material'
|
||||||
|
import { toast } from 'react-toastify'
|
||||||
|
|
||||||
// Styled Custom Components
|
// Styled Custom Components
|
||||||
const LoginIllustration = styled('img')(({ theme }) => ({
|
const LoginIllustration = styled('img')(({ theme }) => ({
|
||||||
@ -117,8 +118,8 @@ const Login = ({ mode }: { mode: SystemMode }) => {
|
|||||||
} = useForm<FormData>({
|
} = useForm<FormData>({
|
||||||
resolver: valibotResolver(schema),
|
resolver: valibotResolver(schema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
email: 'guapatlu@jambi.com',
|
email: '',
|
||||||
password: '12345678'
|
password: ''
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -146,7 +147,7 @@ const Login = ({ mode }: { mode: SystemMode }) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError: (error: any) => {
|
onError: (error: any) => {
|
||||||
setErrorState(error.response.data)
|
toast.error(error.response.data.message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -262,16 +263,6 @@ const Login = ({ mode }: { mode: SystemMode }) => {
|
|||||||
Create an account
|
Create an account
|
||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
<Divider className='gap-2'>or</Divider>
|
|
||||||
<Button
|
|
||||||
color='secondary'
|
|
||||||
className='self-center text-textPrimary'
|
|
||||||
startIcon={<img src='/images/logos/google.png' alt='Google' width={22} />}
|
|
||||||
sx={{ '& .MuiButton-startIcon': { marginInlineEnd: 3 } }}
|
|
||||||
onClick={() => console.log('google')}
|
|
||||||
>
|
|
||||||
Sign in with Google
|
|
||||||
</Button>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user