File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,15 @@ const CODE_RE = /[?&]code=[^&]+/;
44const STATE_RE = / [ ? & ] s t a t e = [ ^ & ] + / ;
55const ERROR_RE = / [ ? & ] e r r o r = [ ^ & ] + / ;
66
7+ interface WithError {
8+ error : string ;
9+ }
10+
11+ interface WithErrorAndDescription {
12+ error : string ;
13+ error_description : string ;
14+ }
15+
716export 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 } ;
You can’t perform that action at this time.
0 commit comments