-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
boody
committed
Apr 26, 2024
1 parent
802352c
commit 46223c2
Showing
4 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { Fragment } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
import { Navigate } from 'react-router-dom'; | ||
import $AuthData from '../../store/index'; | ||
|
||
export default function IsAdmin({ children }) { | ||
const [authRecoil] = useRecoilState($AuthData); | ||
|
||
if (authRecoil.role !== 'owner' && authRecoil.role !== 'admin') { | ||
return <Navigate to="/" />; | ||
} | ||
|
||
return <Fragment>{children}</Fragment>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { Fragment } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
import { Navigate } from 'react-router-dom'; | ||
import $AuthData from '../../store/index'; | ||
|
||
export default function IsOwenr({ children }) { | ||
const [authRecoil] = useRecoilState($AuthData); | ||
|
||
if (authRecoil.role !== 'owner') { | ||
return <Navigate to="/" />; | ||
} | ||
|
||
return <Fragment>{children}</Fragment>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
import { atom } from "recoil"; | ||
|
||
const localData = JSON.parse(localStorage.getItem('loginUser')); | ||
const defaultAuthData = { | ||
isAuth: false, | ||
user: null, | ||
role: null | ||
}; | ||
|
||
if (localData && localData.role) { | ||
defaultAuthData.role = localData.role; | ||
} | ||
|
||
const $AuthData = atom({ | ||
key: "$AuthData", | ||
default: localData || { | ||
isAuth: false, | ||
user: null, | ||
role: null || localData.role | ||
}, | ||
default: localData || defaultAuthData, | ||
}); | ||
|
||
export default $AuthData; |