Skip to content

Commit 19bb98c

Browse files
committed
Fix lint
1 parent 8207013 commit 19bb98c

File tree

7 files changed

+147
-153
lines changed

7 files changed

+147
-153
lines changed

packages/react-router/src/components/Callback.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
* under the License.
1717
*/
1818

19-
import {FC} from 'react';
20-
import {useNavigate, useLocation} from 'react-router';
2119
import {BaseCallback} from '@asgardeo/react';
20+
import {FC} from 'react';
21+
import {useLocation, useNavigate} from 'react-router';
2222

2323
/**
2424
* Props for the Callback component.
@@ -49,27 +49,23 @@ export interface CallbackProps {
4949
* <Route path="/callback" element={<Callback />} />
5050
* ```
5151
*/
52-
const Callback: FC<CallbackProps> = ({
53-
onError,
54-
onNavigate,
55-
}) => {
56-
const navigate = useNavigate();
57-
const location = useLocation();
52+
const Callback: FC<CallbackProps> = ({onError, onNavigate}: CallbackProps) => {
53+
const navigate: ReturnType<typeof useNavigate> = useNavigate();
54+
const location: ReturnType<typeof useLocation> = useLocation();
5855

5956
const handleNavigate = (path: string): void => {
6057
if (onNavigate) {
6158
onNavigate(path);
6259
return;
6360
}
6461

65-
const fullPath = window.location.pathname;
66-
const relativePath = location.pathname;
67-
const basename = fullPath.endsWith(relativePath)
62+
const fullPath: string = window.location.pathname;
63+
const relativePath: string = location.pathname;
64+
const basename: string = fullPath.endsWith(relativePath)
6865
? fullPath.slice(0, -relativePath.length).replace(/\/$/, '')
6966
: '';
7067

71-
const navigationPath =
72-
basename && path.startsWith(basename) ? path.slice(basename.length) || '/' : path;
68+
const navigationPath: string = basename && path.startsWith(basename) ? path.slice(basename.length) || '/' : path;
7369

7470
navigate(navigationPath);
7571
};
@@ -79,7 +75,7 @@ const Callback: FC<CallbackProps> = ({
7975
onNavigate={handleNavigate}
8076
onError={
8177
onError ||
82-
((error: Error) => {
78+
((error: Error): void => {
8379
// eslint-disable-next-line no-console
8480
console.error('OAuth callback error:', error);
8581
})

packages/react/src/components/auth/Callback/BaseCallback.tsx

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import {FC, useEffect, useRef} from 'react';
2323
*/
2424
export interface BaseCallbackProps {
2525
/**
26-
* Function to navigate to a different path
26+
* Callback function called when an error occurs
2727
*/
28-
onNavigate: (path: string) => void;
28+
onError?: (error: Error) => void;
2929

3030
/**
31-
* Callback function called when an error occurs
31+
* Function to navigate to a different path
3232
*/
33-
onError?: (error: Error) => void;
33+
onNavigate: (path: string) => void;
3434
}
3535

3636
/**
@@ -49,12 +49,9 @@ export interface BaseCallbackProps {
4949
* - Handling the assertion and auth/callback POST
5050
* - Managing the authenticated session
5151
*/
52-
export const BaseCallback: FC<BaseCallbackProps> = ({
53-
onNavigate,
54-
onError,
55-
}) => {
52+
export const BaseCallback: FC<BaseCallbackProps> = ({onNavigate, onError}: BaseCallbackProps) => {
5653
// Prevent double execution in React Strict Mode
57-
const processingRef = useRef(false);
54+
const processingRef: any = useRef(false);
5855

5956
useEffect(() => {
6057
const processOAuthCallback = (): void => {
@@ -65,31 +62,31 @@ export const BaseCallback: FC<BaseCallbackProps> = ({
6562
processingRef.current = true;
6663

6764
// Declare variables outside try block for use in catch
68-
var returnPath = '/';
65+
let returnPath: string = '/';
6966

7067
try {
71-
// Extract OAuth parameters from URL
72-
const urlParams = new URLSearchParams(window.location.search);
73-
const code = urlParams.get('code');
74-
const state = urlParams.get('state');
75-
const nonce = urlParams.get('nonce');
76-
const oauthError = urlParams.get('error');
77-
const errorDescription = urlParams.get('error_description');
78-
79-
// Validate and retrieve OAuth state from sessionStorage
68+
// 1. Extract OAuth parameters from URL
69+
const urlParams: URLSearchParams = new URLSearchParams(window.location.search);
70+
const code: string | null = urlParams.get('code');
71+
const state: string | null = urlParams.get('state');
72+
const nonce: string | null = urlParams.get('nonce');
73+
const oauthError: string | null = urlParams.get('error');
74+
const errorDescription: string | null = urlParams.get('error_description');
75+
76+
// 2. Validate and retrieve OAuth state from sessionStorage
8077
if (!state) {
8178
throw new Error('Missing OAuth state parameter - possible security issue');
8279
}
8380

84-
const storedData = sessionStorage.getItem(`asgardeo_oauth_${state}`);
81+
const storedData: string | null = sessionStorage.getItem(`asgardeo_oauth_${state}`);
8582
if (!storedData) {
8683
// If state not found, might be an error callback - try to handle gracefully
8784
if (oauthError) {
88-
const errorMsg = errorDescription || oauthError || 'OAuth authentication failed';
89-
const err = new Error(errorMsg);
85+
const errorMsg: string = errorDescription || oauthError || 'OAuth authentication failed';
86+
const err: Error = new Error(errorMsg);
9087
onError?.(err);
9188

92-
const params = new URLSearchParams();
89+
const params: URLSearchParams = new URLSearchParams();
9390
params.set('error', oauthError);
9491
if (errorDescription) {
9592
params.set('error_description', errorDescription);
@@ -104,23 +101,23 @@ export const BaseCallback: FC<BaseCallbackProps> = ({
104101
const {path, timestamp} = JSON.parse(storedData);
105102
returnPath = path || '/';
106103

107-
// Validate state freshness
108-
const MAX_STATE_AGE = 600000; // 10 minutes
104+
// 3. Validate state freshness
105+
const MAX_STATE_AGE: number = 600000; // 10 minutes
109106
if (Date.now() - timestamp > MAX_STATE_AGE) {
110107
sessionStorage.removeItem(`asgardeo_oauth_${state}`);
111108
throw new Error('OAuth state expired - please try again');
112109
}
113110

114-
// Clean up state
111+
// 4. Clean up state
115112
sessionStorage.removeItem(`asgardeo_oauth_${state}`);
116113

117-
// Handle OAuth error response
114+
// 5. Handle OAuth error response
118115
if (oauthError) {
119-
const errorMsg = errorDescription || oauthError || 'OAuth authentication failed';
120-
const err = new Error(errorMsg);
116+
const errorMsg: string = errorDescription || oauthError || 'OAuth authentication failed';
117+
const err: Error = new Error(errorMsg);
121118
onError?.(err);
122119

123-
const params = new URLSearchParams();
120+
const params: URLSearchParams = new URLSearchParams();
124121
params.set('error', oauthError);
125122
if (errorDescription) {
126123
params.set('error_description', errorDescription);
@@ -130,28 +127,29 @@ export const BaseCallback: FC<BaseCallbackProps> = ({
130127
return;
131128
}
132129

133-
// Validate required parameters
130+
// 6. Validate required parameters
134131
if (!code) {
135132
throw new Error('Missing OAuth authorization code');
136133
}
137134

138-
// Forward OAuth code to original component
135+
// 7. Forward OAuth code to original component
139136
// The component (SignIn/AcceptInvite) will retrieve flowId/authId from sessionStorage
140-
const params = new URLSearchParams();
137+
const params: URLSearchParams = new URLSearchParams();
141138
params.set('code', code);
142139
if (nonce) {
143140
params.set('nonce', nonce);
144141
}
145142

146143
onNavigate(`${returnPath}?${params.toString()}`);
147144
} catch (err) {
148-
const errorMessage = err instanceof Error ? err.message : 'OAuth callback processing failed';
145+
const errorMessage: string = err instanceof Error ? err.message : 'OAuth callback processing failed';
146+
// eslint-disable-next-line no-console
149147
console.error('OAuth callback error:', err);
150148

151149
onError?.(err instanceof Error ? err : new Error(errorMessage));
152150

153151
// Redirect back with OAuth error format
154-
const params = new URLSearchParams();
152+
const params: URLSearchParams = new URLSearchParams();
155153
params.set('error', 'callback_error');
156154
params.set('error_description', errorMessage);
157155

packages/react/src/components/presentation/auth/AcceptInvite/v2/BaseAcceptInvite.tsx

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import useStyles from './BaseAcceptInvite.styles';
2222
import useTheme from '../../../../../contexts/Theme/useTheme';
2323
import {useOAuthCallback} from '../../../../../hooks/useOAuthCallback';
2424
import useTranslation from '../../../../../hooks/useTranslation';
25-
import {normalizeFlowResponse, extractErrorMessage} from '../../../../../utils/v2/flowTransformer';
2625
import {initiateOAuthRedirect} from '../../../../../utils/oauth';
26+
import {normalizeFlowResponse, extractErrorMessage} from '../../../../../utils/v2/flowTransformer';
2727
import AlertPrimitive from '../../../../primitives/Alert/Alert';
2828
import Button from '../../../../primitives/Button/Button';
2929
// eslint-disable-next-line import/no-named-as-default
@@ -288,44 +288,6 @@ const BaseAcceptInvite: FC<BaseAcceptInviteProps> = ({
288288
[t, onError],
289289
);
290290

291-
/**
292-
* Handle OAuth callback when returning from OAuth provider.
293-
* This hook processes the authorization code and continues the flow.
294-
*/
295-
useOAuthCallback({
296-
onSubmit: async (payload: any) => {
297-
const rawResponse: any = await onSubmit(payload);
298-
const response: any = normalizeFlowResponseLocal(rawResponse);
299-
return response;
300-
},
301-
onComplete: () => {
302-
setIsComplete(true);
303-
setIsValidatingToken(false);
304-
onComplete?.();
305-
},
306-
onError: (error: any) => {
307-
setIsTokenInvalid(true);
308-
setIsValidatingToken(false);
309-
handleError(error);
310-
},
311-
onProcessingStart: () => {
312-
setIsValidatingToken(true);
313-
},
314-
currentFlowId: flowId ?? null,
315-
isInitialized: true,
316-
tokenValidationAttemptedRef,
317-
onFlowChange: (response: any) => {
318-
onFlowChange?.(response);
319-
// Initialize currentFlow for next steps if not complete
320-
if (response.flowStatus !== 'COMPLETE') {
321-
setCurrentFlow(response);
322-
setFormValues({});
323-
setFormErrors({});
324-
setTouchedFields({});
325-
}
326-
},
327-
});
328-
329291
/**
330292
* Normalize flow response to ensure component-driven format.
331293
* Transforms data.meta.components to data.components.
@@ -357,6 +319,44 @@ const BaseAcceptInvite: FC<BaseAcceptInviteProps> = ({
357319
[t, children],
358320
);
359321

322+
/**
323+
* Handle OAuth callback when returning from OAuth provider.
324+
* This hook processes the authorization code and continues the flow.
325+
*/
326+
useOAuthCallback({
327+
currentFlowId: flowId ?? null,
328+
isInitialized: true,
329+
onComplete: () => {
330+
setIsComplete(true);
331+
setIsValidatingToken(false);
332+
onComplete?.();
333+
},
334+
onError: (error: any) => {
335+
setIsTokenInvalid(true);
336+
setIsValidatingToken(false);
337+
handleError(error);
338+
},
339+
onFlowChange: (response: any) => {
340+
onFlowChange?.(response);
341+
// Initialize currentFlow for next steps if not complete
342+
if (response.flowStatus !== 'COMPLETE') {
343+
setCurrentFlow(response);
344+
setFormValues({});
345+
setFormErrors({});
346+
setTouchedFields({});
347+
}
348+
},
349+
onProcessingStart: () => {
350+
setIsValidatingToken(true);
351+
},
352+
onSubmit: async (payload: any) => {
353+
const rawResponse: any = await onSubmit(payload);
354+
const response: any = normalizeFlowResponseLocal(rawResponse);
355+
return response;
356+
},
357+
tokenValidationAttemptedRef,
358+
});
359+
360360
/**
361361
* Handle input value changes.
362362
*/

packages/react/src/components/presentation/auth/SignIn/v2/SignIn.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import BaseSignIn, {BaseSignInProps} from './BaseSignIn';
3131
import useAsgardeo from '../../../../../contexts/Asgardeo/useAsgardeo';
3232
import {useOAuthCallback} from '../../../../../hooks/useOAuthCallback';
3333
import useTranslation from '../../../../../hooks/useTranslation';
34-
import {normalizeFlowResponse} from '../../../../../utils/v2/flowTransformer';
3534
import {initiateOAuthRedirect} from '../../../../../utils/oauth';
35+
import {normalizeFlowResponse} from '../../../../../utils/v2/flowTransformer';
3636
import {handlePasskeyAuthentication, handlePasskeyRegistration} from '../../../../../utils/v2/passkey';
3737

3838
/**
@@ -563,16 +563,16 @@ const SignIn: FC<SignInProps> = ({
563563
};
564564

565565
useOAuthCallback({
566-
onSubmit: async (payload: any) => handleSubmit({flowId: payload.flowId, inputs: payload.inputs}),
566+
currentFlowId,
567+
isInitialized: isInitialized && !isLoading,
568+
isSubmitting,
567569
onError: (err: any) => {
568570
clearFlowState();
569571
setError(err instanceof Error ? err : new Error(String(err)));
570572
},
571-
currentFlowId,
572-
isInitialized: isInitialized && !isLoading,
573-
isSubmitting,
574-
setFlowId,
573+
onSubmit: async (payload: any) => handleSubmit({flowId: payload.flowId, inputs: payload.inputs}),
575574
processedRef: oauthCodeProcessedRef,
575+
setFlowId,
576576
});
577577

578578
/**

0 commit comments

Comments
 (0)