feat: frontend
This commit is contained in:
27
ordr-ui/app/providers/AuthenticationProvider.ts
Normal file
27
ordr-ui/app/providers/AuthenticationProvider.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { create } from 'zustand'
|
||||
import { UserResponse } from '../client/response'
|
||||
import { GetCurrentUser, SetUserName } from '../client/controllers'
|
||||
|
||||
export type UserActions = {
|
||||
sync: () => Promise<UserResponse | undefined>
|
||||
updateName: (name: string) => Promise<void>
|
||||
}
|
||||
|
||||
export const useCurrentAuthenticatedUserStore = create<UserResponse & UserActions>((set) => ({
|
||||
Id: -1,
|
||||
Name: '',
|
||||
JobPosition: '',
|
||||
Active: false,
|
||||
Admin: false,
|
||||
sync: async () => {
|
||||
const authUser = await GetCurrentUser()
|
||||
set((state) => ({
|
||||
...authUser,
|
||||
...state
|
||||
}))
|
||||
return authUser
|
||||
},
|
||||
updateName: async (name: string) => {
|
||||
await SetUserName(name)
|
||||
}
|
||||
}))
|
||||
Reference in New Issue
Block a user