26 lines
733 B
TypeScript
26 lines
733 B
TypeScript
import { LocalStorageDict } from "@/dict/local-storage-dict";
|
|
import { DATASQUIREL_LoggedInUser } from "@moduletrace/datasquirel/package-shared/types";
|
|
import React from "react";
|
|
|
|
export default function useLocalUser() {
|
|
const [user, setUser] = React.useState<
|
|
DATASQUIREL_LoggedInUser | null | undefined
|
|
>(undefined);
|
|
|
|
React.useEffect(() => {
|
|
try {
|
|
const localUserJSON = localStorage.getItem(
|
|
LocalStorageDict["User"]
|
|
);
|
|
if (localUserJSON) {
|
|
const localUser = JSON.parse(localUserJSON);
|
|
setUser(localUser);
|
|
}
|
|
} catch (error) {
|
|
setUser(null);
|
|
}
|
|
}, []);
|
|
|
|
return { user };
|
|
}
|