@@ -10,6 +10,7 @@ import { authEvents, authzEvents, authzEventUtils } from "@/lib/authEvents";
1010import { AUTH_EVENTS , AUTHZ_EVENTS } from "@/const/auth" ;
1111import { getEffectiveRoutePath } from "@/lib/auth" ;
1212import log from "@/lib/logger" ;
13+ import { useDeployment } from "@/components/providers/deploymentProvider" ;
1314
1415/**
1516 * Custom hook for authorization management
@@ -19,6 +20,8 @@ export function useAuthorization(): AuthorizationContextType {
1920 const router = useRouter ( ) ;
2021 const pathname = usePathname ( ) ;
2122
23+ const { isSpeedMode } = useDeployment ( ) ;
24+
2225 const [ user , setUser ] = useState < User | null > ( null ) ;
2326 const [ groupIds , setGroupIds ] = useState < number [ ] > ( [ ] ) ;
2427 const [ permissions , setPermissions ] = useState < string [ ] > ( [ ] ) ;
@@ -101,6 +104,7 @@ export function useAuthorization(): AuthorizationContextType {
101104
102105 // Listen for authentication events
103106 useEffect ( ( ) => {
107+ if ( isSpeedMode ) return ;
104108 // Handle login success - set user info immediately, then fetch full permissions
105109 const handleLoginSuccess = ( ) => {
106110 refetch ( ) . then ( ( result ) => {
@@ -176,26 +180,35 @@ export function useAuthorization(): AuthorizationContextType {
176180 // Initialize authorization data on mount if user is already authenticated
177181 useEffect ( ( ) => {
178182 const initializeAuthz = ( ) => {
179- const session = getSessionFromStorage ( ) ;
180- if ( session ?. access_token ) {
183+ // In speed mode, always fetch authorization info
184+ // In full mode, only fetch if session exists
185+ if ( ! isSpeedMode ) {
186+ const session = getSessionFromStorage ( ) ;
187+ if ( ! session ?. access_token ) {
188+ return ;
189+ }
181190 const now = Date . now ( ) ;
182191 const expiresAt = session . expires_at * 1000 ;
183192
184- if ( expiresAt > now ) {
185- log . info (
186- "Valid session found on initialization, fetching authorization info..."
187- ) ;
188- refetch ( ) . catch ( ( error ) => {
189- log . error ( "Initial refetch error:" , error ) ;
190- } ) ;
193+ if ( expiresAt <= now ) {
194+ return ;
191195 }
192196 }
197+
198+ log . info (
199+ isSpeedMode
200+ ? "Speed mode: fetching authorization info..."
201+ : "Valid session found on initialization, fetching authorization info..."
202+ ) ;
203+ refetch ( ) . catch ( ( error ) => {
204+ log . error ( "Initial refetch error:" , error ) ;
205+ } ) ;
193206 } ;
194207
195208 // Small delay to ensure authentication state is initialized
196209 const timeoutId = setTimeout ( initializeAuthz , 100 ) ;
197210 return ( ) => clearTimeout ( timeoutId ) ;
198- } , [ refetch ] ) ;
211+ } , [ isSpeedMode , refetch ] ) ;
199212
200213 // Authz prompt modal control functions (defined before useLayoutEffect)
201214 const openAuthzPromptModal = useCallback ( ( ) => setIsAuthzPromptModalOpen ( true ) , [ ] ) ;
0 commit comments