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