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

fix(web): system username for DESKTOP mode

This commit is contained in:
Saad Jutt
2022-05-30 21:08:17 +05:00
parent 73c81a45dc
commit a8ba378fd1
3 changed files with 23 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import { RequestHandler, Request } from 'express'
import { userInfo } from 'os'
import { RequestUser } from '../types'
import { ModeType } from '../utils'
@@ -29,8 +30,8 @@ export const desktopRestrict: RequestHandler = (req, res, next) => {
export const desktopUser: RequestUser = {
userId: 12345,
clientId: 'desktop_app',
username: 'DESKTOPusername',
displayName: 'DESKTOP User',
username: userInfo().username,
displayName: userInfo().username,
isAdmin: true,
isActive: true
}

View File

@@ -16,7 +16,7 @@ import {
} from '@mui/material'
import { toast } from 'react-toastify'
import { AppContext } from '../../context/appContext'
import { AppContext, ModeType } from '../../context/appContext'
const Profile = () => {
const [isLoading, setIsLoading] = useState(false)
@@ -89,6 +89,7 @@ const Profile = () => {
required
value={user.displayName}
variant="outlined"
disabled={appContext.mode === ModeType.Desktop}
/>
</Grid>
@@ -103,6 +104,7 @@ const Profile = () => {
required
value={user.username}
variant="outlined"
disabled={appContext.mode === ModeType.Desktop}
/>
</Grid>

View File

@@ -9,6 +9,11 @@ import React, {
} from 'react'
import axios from 'axios'
export enum ModeType {
Server = 'server',
Desktop = 'desktop'
}
interface AppContextProps {
checkingSession: boolean
loggedIn: boolean
@@ -19,6 +24,7 @@ interface AppContextProps {
setUsername: Dispatch<SetStateAction<string>> | null
displayName: string
setDisplayName: Dispatch<SetStateAction<string>> | null
mode: ModeType
logout: (() => void) | null
}
@@ -32,6 +38,7 @@ export const AppContext = createContext<AppContextProps>({
setUsername: null,
displayName: '',
setDisplayName: null,
mode: ModeType.Server,
logout: null
})
@@ -42,6 +49,7 @@ const AppContextProvider = (props: { children: ReactNode }) => {
const [userId, setUserId] = useState(0)
const [username, setUsername] = useState('')
const [displayName, setDisplayName] = useState('')
const [mode, setMode] = useState(ModeType.Server)
useEffect(() => {
setCheckingSession(true)
@@ -60,6 +68,14 @@ const AppContextProvider = (props: { children: ReactNode }) => {
setLoggedIn(false)
axios.get('/') // get CSRF TOKEN
})
axios
.get('/SASjsApi/info')
.then((res) => res.data)
.then((data: any) => {
setMode(data.mode)
})
.catch(() => {})
}, [])
const logout = useCallback(() => {
@@ -82,6 +98,7 @@ const AppContextProvider = (props: { children: ReactNode }) => {
setUsername,
displayName,
setDisplayName,
mode,
logout
}}
>