forked from ddrilling/asb_cloud_front
Добавлен перенос на страницу входа при попытке открыть страницу без авторизации
This commit is contained in:
parent
e3e5a1bf4e
commit
98da6eb847
@ -1,6 +1,7 @@
|
||||
import { memo } from 'react'
|
||||
import { Redirect, Route, RouteProps } from 'react-router-dom'
|
||||
|
||||
import { getUserId } from '@utils/storage'
|
||||
import { isURLAvailable } from '@utils/permissions'
|
||||
|
||||
export type PrivateDefaultRouteProps = RouteProps & {
|
||||
@ -10,7 +11,7 @@ export type PrivateDefaultRouteProps = RouteProps & {
|
||||
|
||||
export const PrivateDefaultRoute = memo<PrivateDefaultRouteProps>(({ elseRedirect, urls, ...other }) => (
|
||||
<Route {...other} path={'/'}>
|
||||
<Redirect to={{ pathname: urls.find((url) => isURLAvailable(url)) ?? elseRedirect ?? '/access_denied' }} />
|
||||
<Redirect to={{ pathname: urls.find((url) => isURLAvailable(url)) ?? elseRedirect ?? (getUserId() ? '/access_denied' : '/login') }} />
|
||||
</Route>
|
||||
))
|
||||
|
||||
|
@ -3,6 +3,7 @@ import { memo, ReactNode } from 'react'
|
||||
import { Redirect, Route, RouteProps } from 'react-router-dom'
|
||||
import { join } from 'path'
|
||||
|
||||
import { getUserId } from '@utils/storage'
|
||||
import { isURLAvailable } from '@utils/permissions'
|
||||
|
||||
export type PrivateRouteProps = RouteProps & {
|
||||
@ -13,7 +14,7 @@ export type PrivateRouteProps = RouteProps & {
|
||||
}
|
||||
|
||||
export const defaultRedirect = (location?: Location<unknown>) => (
|
||||
<Redirect to={{ pathname: '/access_denied', state: { from: location } }} />
|
||||
<Redirect to={{ pathname: getUserId() ? '/access_denied' : '/login', state: { from: location } }} />
|
||||
)
|
||||
|
||||
export const PrivateRoute = memo<PrivateRouteProps>(({ root = '', path, component, children, redirect = defaultRedirect, ...other }) => {
|
||||
|
Loading…
Reference in New Issue
Block a user