Skip to content

Commit 46e76bc

Browse files
authored
πŸ› Bugfix: in speed mode, shouldn't skipped authorization
πŸ› Bugfix: in speed mode, shouldn't skipped authorization
2 parents 59e70f6 + 4681042 commit 46e76bc

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

β€Žfrontend/hooks/auth/useAuthenticationState.tsβ€Ž

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ export function useAuthenticationState(): AuthenticationStateReturn {
2929
const [authServiceUnavailable, setAuthServiceUnavailable] =
3030
useState<boolean>(false);
3131

32-
if (isSpeedMode) {
33-
log.info("Speed mode: valid session found, emitting login success event");
34-
authEventUtils.emitLoginSuccess();
35-
}
32+
// Speed mode: skip authentication checks, consider user as authenticated
33+
useEffect(() => {
34+
if (isSpeedMode) {
35+
// In speed mode, user is considered authenticated without session
36+
setIsAuthenticated(true);
37+
setIsAuthChecking(false);
38+
}
39+
}, [isSpeedMode]);
3640

3741
// Initialize authentication state based on session
3842
useEffect(() => {

β€Žfrontend/hooks/auth/useAuthorization.tsβ€Ž

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { authEvents, authzEvents, authzEventUtils } from "@/lib/authEvents";
1010
import { AUTH_EVENTS, AUTHZ_EVENTS } from "@/const/auth";
1111
import { getEffectiveRoutePath } from "@/lib/auth";
1212
import 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), []);

β€Žfrontend/hooks/auth/useSessionManager.tsβ€Ž

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ export const refreshSession = async (): Promise<boolean> => {
6060
// ============================================================================
6161

6262
export function useSessionManager() {
63-
const { isSpeedMode } = useDeployment();
63+
const { isSpeedMode, isDeploymentReady } = useDeployment();
6464
const reconcileExpiryRef = useRef<() => void>(() => {});
6565

6666
// Initialize session management when hook is used
6767
useEffect(() => {
68-
// In speed mode, skip session validation
69-
if (isSpeedMode) return;
68+
// In speed mode or before deployment is ready, skip session validation
69+
// This prevents the modal from showing when isSpeedMode is initially false
70+
// and then becomes true after API returns deployment_version
71+
if (isSpeedMode || !isDeploymentReady) return;
7072

7173
const session = getSessionFromStorage();
7274
if (!session) {
@@ -80,14 +82,15 @@ export function useSessionManager() {
8082

8183
// Session is expired or invalid
8284
handleSessionExpired();
83-
}, [isSpeedMode]);
85+
}, [isSpeedMode, isDeploymentReady]);
8486

8587
/**
8688
* Proactive session expiry watcher
8789
* Triggers session-expired even if user does not make any API request
8890
*/
8991
useEffect(() => {
90-
if (isSpeedMode) return;
92+
// In speed mode or before deployment is ready, skip session watching
93+
if (isSpeedMode || !isDeploymentReady) return;
9194

9295
let timeoutId: number | null = null;
9396
let intervalId: number | null = null;

0 commit comments

Comments
Β (0)