Skip to content

Commit 1eaefd8

Browse files
Merge branch 'main' into dependabot/npm_and_yarn/start-server-and-test-2.1.0
2 parents 1562a9b + 23c4e9e commit 1eaefd8

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/utils.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ const CODE_RE = /[?&]code=[^&]+/;
44
const STATE_RE = /[?&]state=[^&]+/;
55
const ERROR_RE = /[?&]error=[^&]+/;
66

7+
interface WithError {
8+
error: string;
9+
}
10+
11+
interface WithErrorAndDescription {
12+
error: string;
13+
error_description: string;
14+
}
15+
716
export const hasAuthParams = (searchParams = window.location.search): boolean =>
817
(CODE_RE.test(searchParams) || ERROR_RE.test(searchParams)) &&
918
STATE_RE.test(searchParams);
@@ -19,15 +28,17 @@ const normalizeErrorFn =
1928
error !== null &&
2029
typeof error === 'object' &&
2130
'error' in error &&
22-
typeof error.error === 'string'
31+
typeof (error as WithError).error === 'string'
2332
) {
2433
if (
2534
'error_description' in error &&
26-
typeof error.error_description === 'string'
35+
typeof (error as WithErrorAndDescription).error_description === 'string'
2736
) {
28-
return new OAuthError(error.error, error.error_description);
37+
const e = error as WithErrorAndDescription;
38+
return new OAuthError(e.error, e.error_description);
2939
}
30-
return new OAuthError(error.error);
40+
const e = error as WithError;
41+
return new OAuthError(e.error);
3142
}
3243
return new Error(fallbackMessage);
3344
};

0 commit comments

Comments
 (0)