dcbb65d799
* LDAP - WIP * WIP * add hasGeneratedPassword * fix jotai atom * - don't require password confirmation for MFA is user has auto generated password (LDAP) - cleanups * fix * reorder * update migration * update default * fix type error
42 lines
1020 B
TypeScript
42 lines
1020 B
TypeScript
import { atom } from "jotai";
|
|
import { atomWithStorage } from "jotai/utils";
|
|
import { ICurrentUser, IUser } from "@/features/user/types/user.types";
|
|
import { IWorkspace } from "@/features/workspace/types/workspace.types";
|
|
|
|
export const currentUserAtom = atomWithStorage<ICurrentUser | null>(
|
|
"currentUser",
|
|
null,
|
|
);
|
|
|
|
export const userAtom = atom(
|
|
(get) => {
|
|
const currentUser = get(currentUserAtom);
|
|
return currentUser?.user ?? null;
|
|
},
|
|
(get, set, newUser: IUser) => {
|
|
const currentUser = get(currentUserAtom);
|
|
if (currentUser) {
|
|
set(currentUserAtom, {
|
|
...currentUser,
|
|
user: newUser,
|
|
});
|
|
}
|
|
}
|
|
);
|
|
|
|
export const workspaceAtom = atom(
|
|
(get) => {
|
|
const currentUser = get(currentUserAtom);
|
|
return currentUser?.workspace ?? null;
|
|
},
|
|
(get, set, newWorkspace: IWorkspace) => {
|
|
const currentUser = get(currentUserAtom);
|
|
if (currentUser) {
|
|
set(currentUserAtom, {
|
|
...currentUser,
|
|
workspace: newWorkspace,
|
|
});
|
|
}
|
|
}
|
|
);
|