test(auth): more auth work
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import {create} from "zustand";
|
||||
|
||||
type User = {
|
||||
id: number;
|
||||
user_id: string;
|
||||
email: string;
|
||||
username: string;
|
||||
roles: keyof Roles[];
|
||||
role: string;
|
||||
};
|
||||
|
||||
interface Roles {
|
||||
role: string;
|
||||
}
|
||||
|
||||
export type SessionState = {
|
||||
user: User | null;
|
||||
token: string | null;
|
||||
|
||||
48
frontend/src/lib/store/useGetRoles.ts
Normal file
48
frontend/src/lib/store/useGetRoles.ts
Normal 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);
|
||||
}
|
||||
},
|
||||
}));
|
||||
@@ -1,16 +1,17 @@
|
||||
import {Modules} from "@/types/modules";
|
||||
import {create} from "zustand";
|
||||
//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 Modules {
|
||||
// module_id: string;
|
||||
// name: string;
|
||||
// active: boolean;
|
||||
// roles: string;
|
||||
// add_user: string;
|
||||
// add_date: Date;
|
||||
// upd_user: string;
|
||||
// upd_date: Date;
|
||||
// }
|
||||
|
||||
interface SettingState {
|
||||
modules: Modules[];
|
||||
|
||||
Reference in New Issue
Block a user