added role func, fixed some ui

This commit is contained in:
Jelaletdin12
2026-09-01 23:35:17 +05:00
parent cc5b5fca24
commit 7445e09d5f
22 changed files with 1074 additions and 622 deletions

View File

@@ -3,11 +3,14 @@ import { persist } from "zustand/middleware";
import axios from "axios";
import type { ApiSuccessResponse } from "@/lib/api/client";
import type { LocalizedText } from "@/features/branches/api/branchesApi";
import { getDefaultHomePath } from "@/lib/auth/permissions";
import { queryClient } from "@/app/providers/QueryProvider";
export interface AuthUserRole {
id: number;
code: string;
name: string;
guardName?: string;
}
export interface AuthUserBranch {
@@ -20,6 +23,21 @@ export interface AuthUserPermission {
id: number;
code?: string;
name?: string;
guardName?: string;
module?: string;
}
export interface AuthUserModulePermission {
id: number;
code?: string;
name?: string;
guardName?: string;
module?: string;
}
export interface AuthUserModule {
module: string;
permissions: AuthUserModulePermission[];
}
export interface AuthUser {
@@ -33,14 +51,14 @@ export interface AuthUser {
avatar?: string;
branches?: AuthUserBranch[];
permissions?: AuthUserPermission[];
modules?: AuthUserModule[];
createdAt?: string;
}
/** Returns the role-appropriate landing page for the current user. */
export function getHomePath(): string {
const user = useAuthStore.getState().user;
const isAdmin = user?.role?.code === "admin";
return isAdmin ? "/dashboard" : "/loan-orders";
return getDefaultHomePath(user);
}
interface AuthState {
@@ -73,7 +91,10 @@ export const useAuthStore = create<AuthState>()(
setUser: (user) => set({ user }),
clearAuth: () => set({ token: null, refreshTokenValue: null, user: null, isAuthenticated: false }),
clearAuth: () => {
set({ token: null, refreshTokenValue: null, user: null, isAuthenticated: false });
queryClient.clear();
},
logout: () => {
get().clearAuth();