1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-11 03:34:35 +00:00

fix: add isAdmin attribute to return response of get session and login requests

This commit is contained in:
2022-06-23 22:50:00 +05:00
parent 4c6b9c5e93
commit bdf63df1d9
5 changed files with 23 additions and 6 deletions

View File

@@ -30,6 +30,7 @@ const Login = () => {
appContext.setUserId?.(user.id)
appContext.setUsername?.(user.username)
appContext.setDisplayName?.(user.displayName)
appContext.setIsAdmin?.(user.isAdmin)
appContext.setLoggedIn?.(loggedIn)
}
}

View File

@@ -29,6 +29,8 @@ interface AppContextProps {
setUsername: Dispatch<SetStateAction<string>> | null
displayName: string
setDisplayName: Dispatch<SetStateAction<string>> | null
isAdmin: boolean
setIsAdmin: Dispatch<SetStateAction<boolean>> | null
mode: ModeType
runTimes: RunTimeType[]
logout: (() => void) | null
@@ -44,6 +46,8 @@ export const AppContext = createContext<AppContextProps>({
setUsername: null,
displayName: '',
setDisplayName: null,
isAdmin: false,
setIsAdmin: null,
mode: ModeType.Server,
runTimes: [],
logout: null
@@ -56,6 +60,7 @@ const AppContextProvider = (props: { children: ReactNode }) => {
const [userId, setUserId] = useState(0)
const [username, setUsername] = useState('')
const [displayName, setDisplayName] = useState('')
const [isAdmin, setIsAdmin] = useState(false)
const [mode, setMode] = useState(ModeType.Server)
const [runTimes, setRunTimes] = useState<RunTimeType[]>([])
@@ -70,6 +75,7 @@ const AppContextProvider = (props: { children: ReactNode }) => {
setUserId(data.id)
setUsername(data.username)
setDisplayName(data.displayName)
setIsAdmin(data.isAdmin)
setLoggedIn(true)
})
.catch(() => {
@@ -107,6 +113,8 @@ const AppContextProvider = (props: { children: ReactNode }) => {
setUsername,
displayName,
setDisplayName,
isAdmin,
setIsAdmin,
mode,
runTimes,
logout