mirror of
https://github.com/sasjs/server.git
synced 2025-12-10 19:34:34 +00:00
chore: addressed comments
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { randomBytes } from 'crypto'
|
||||
import { Express } from 'express'
|
||||
import mongoose, { Mongoose } from 'mongoose'
|
||||
import { MongoMemoryServer } from 'mongodb-memory-server'
|
||||
@@ -14,6 +13,7 @@ import {
|
||||
generateAccessToken,
|
||||
generateAuthCode,
|
||||
generateRefreshToken,
|
||||
randomBytesHexString,
|
||||
saveTokensInDB,
|
||||
verifyTokenInDB
|
||||
} from '../../../utils'
|
||||
@@ -52,7 +52,7 @@ describe('auth', () => {
|
||||
describe('token', () => {
|
||||
const userInfo: InfoJWT = {
|
||||
clientId,
|
||||
userId: randomBytes(12).toString('hex')
|
||||
userId: randomBytesHexString(12)
|
||||
}
|
||||
beforeAll(async () => {
|
||||
await userController.createUser(user)
|
||||
|
||||
@@ -145,7 +145,7 @@ describe('web', () => {
|
||||
|
||||
expect(res.body.loggedIn).toBeTruthy()
|
||||
expect(res.body.user).toEqual({
|
||||
id: expect.anything(),
|
||||
id: expect.any(String),
|
||||
username: user.username,
|
||||
displayName: user.displayName,
|
||||
isAdmin: user.isAdmin,
|
||||
|
||||
4
api/src/utils/crypto.ts
Normal file
4
api/src/utils/crypto.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { randomBytes } from 'crypto'
|
||||
|
||||
export const randomBytesHexString = (bytesCount: number) =>
|
||||
randomBytes(bytesCount).toString('hex')
|
||||
@@ -2,6 +2,7 @@ export * from './appStreamConfig'
|
||||
export * from './connectDB'
|
||||
export * from './copySASjsCore'
|
||||
export * from './createWeboutSasFile'
|
||||
export * from './crypto'
|
||||
export * from './desktopAutoExec'
|
||||
export * from './extractHeaders'
|
||||
export * from './extractName'
|
||||
|
||||
@@ -26,18 +26,20 @@ const Profile = () => {
|
||||
const [isPasswordModalOpen, setIsPasswordModalOpen] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoading(true)
|
||||
axios
|
||||
.get(`/SASjsApi/user/${appContext.userId}`)
|
||||
.then((res: any) => {
|
||||
setUser(res.data)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
.finally(() => {
|
||||
setIsLoading(false)
|
||||
})
|
||||
if (appContext.userId) {
|
||||
setIsLoading(true)
|
||||
axios
|
||||
.get(`/SASjsApi/user/${appContext.userId}`)
|
||||
.then((res: any) => {
|
||||
setUser(res.data)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
.finally(() => {
|
||||
setIsLoading(false)
|
||||
})
|
||||
}
|
||||
}, [appContext.userId])
|
||||
|
||||
const handleChange = (event: any) => {
|
||||
|
||||
@@ -24,39 +24,32 @@ export enum RunTimeType {
|
||||
interface AppContextProps {
|
||||
checkingSession: boolean
|
||||
loggedIn: boolean
|
||||
setLoggedIn: Dispatch<SetStateAction<boolean>> | null
|
||||
setLoggedIn?: Dispatch<SetStateAction<boolean>>
|
||||
needsToUpdatePassword: boolean
|
||||
setNeedsToUpdatePassword: Dispatch<SetStateAction<boolean>> | null
|
||||
userId: string
|
||||
setUserId: Dispatch<SetStateAction<string>> | null
|
||||
setNeedsToUpdatePassword?: Dispatch<SetStateAction<boolean>>
|
||||
userId?: string
|
||||
setUserId?: Dispatch<SetStateAction<string | undefined>>
|
||||
username: string
|
||||
setUsername: Dispatch<SetStateAction<string>> | null
|
||||
setUsername?: Dispatch<SetStateAction<string>>
|
||||
displayName: string
|
||||
setDisplayName: Dispatch<SetStateAction<string>> | null
|
||||
setDisplayName?: Dispatch<SetStateAction<string>>
|
||||
isAdmin: boolean
|
||||
setIsAdmin: Dispatch<SetStateAction<boolean>> | null
|
||||
setIsAdmin?: Dispatch<SetStateAction<boolean>>
|
||||
mode: ModeType
|
||||
runTimes: RunTimeType[]
|
||||
logout: (() => void) | null
|
||||
logout?: () => void
|
||||
}
|
||||
|
||||
export const AppContext = createContext<AppContextProps>({
|
||||
checkingSession: false,
|
||||
loggedIn: false,
|
||||
setLoggedIn: null,
|
||||
needsToUpdatePassword: false,
|
||||
setNeedsToUpdatePassword: null,
|
||||
userId: '',
|
||||
setUserId: null,
|
||||
username: '',
|
||||
setUsername: null,
|
||||
displayName: '',
|
||||
setDisplayName: null,
|
||||
isAdmin: false,
|
||||
setIsAdmin: null,
|
||||
mode: ModeType.Server,
|
||||
runTimes: [],
|
||||
logout: null
|
||||
runTimes: []
|
||||
})
|
||||
|
||||
const AppContextProvider = (props: { children: ReactNode }) => {
|
||||
@@ -64,7 +57,7 @@ const AppContextProvider = (props: { children: ReactNode }) => {
|
||||
const [checkingSession, setCheckingSession] = useState(false)
|
||||
const [loggedIn, setLoggedIn] = useState(false)
|
||||
const [needsToUpdatePassword, setNeedsToUpdatePassword] = useState(false)
|
||||
const [userId, setUserId] = useState('')
|
||||
const [userId, setUserId] = useState<string>()
|
||||
const [username, setUsername] = useState('')
|
||||
const [displayName, setDisplayName] = useState('')
|
||||
const [isAdmin, setIsAdmin] = useState(false)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
export interface UserResponse {
|
||||
uid: number
|
||||
uid: string
|
||||
username: string
|
||||
displayName: string
|
||||
isAdmin: boolean
|
||||
}
|
||||
|
||||
export interface GroupResponse {
|
||||
uid: number
|
||||
uid: string
|
||||
name: string
|
||||
description: string
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export interface GroupDetailsResponse extends GroupResponse {
|
||||
}
|
||||
|
||||
export interface PermissionResponse {
|
||||
uid: number
|
||||
uid: string
|
||||
path: string
|
||||
type: string
|
||||
setting: string
|
||||
@@ -30,7 +30,7 @@ export interface RegisterPermissionPayload {
|
||||
type: string
|
||||
setting: string
|
||||
principalType: string
|
||||
principalId: number
|
||||
principalId: string
|
||||
}
|
||||
|
||||
export interface TreeNode {
|
||||
|
||||
Reference in New Issue
Block a user