test(auth): more auth work

This commit is contained in:
2025-03-01 15:22:34 -06:00
parent 6c3199fecc
commit d3acdfb481
12 changed files with 275 additions and 78 deletions

View File

@@ -0,0 +1,48 @@
import {create} from "zustand";
import {useSessionStore} from "./sessionStore";
//import useSWR from "swr";
interface Modules {
module_id: string;
name: string;
active: boolean;
roles: string;
add_user: string;
add_date: Date;
upd_user: string;
upd_date: Date;
}
interface SettingState {
userRoles: Modules[];
fetchUserRoles: () => Promise<void>;
setUserRoles: (userRoles: Modules[]) => void;
}
interface FetchModulesResponse {
data: Modules[];
}
export const useModuleStore = create<SettingState>()((set) => ({
userRoles: [],
setUserRoles: (userRoles) => set({userRoles}),
fetchUserRoles: async () => {
try {
//const response = await axios.get<{data: Setting[]}>(`${process.env.NEXT_PUBLIC_URL}/api/settings/client`);
const {token} = useSessionStore();
const response = await fetch(`/api/auth/getuseraccess`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authentication: `Beaer ${token}`,
// You can add other headers here if necessary
},
});
const data: FetchModulesResponse = await response.json();
//console.log(data);
set({userRoles: data.data});
} catch (error) {
console.error("Failed to fetch settings:", error);
}
},
}));