@@ -50,15 +50,15 @@ export function _generateNewEvent(
50
50
}
51
51
52
52
export function _savePartialEvent ( auth : Auth , event : AuthEvent ) : Promise < void > {
53
- return storage ( ) . _set ( key ( auth ) , ( event as object ) as PersistedBlob ) ;
53
+ return storage ( ) . _set ( persistenceKey ( auth ) , ( event as object ) as PersistedBlob ) ;
54
54
}
55
55
56
56
export async function _getAndRemoveEvent (
57
57
auth : Auth
58
58
) : Promise < AuthEvent | null > {
59
- const event = ( await storage ( ) . _get ( key ( auth ) ) ) as AuthEvent | null ;
59
+ const event = ( await storage ( ) . _get ( persistenceKey ( auth ) ) ) as AuthEvent | null ;
60
60
if ( event ) {
61
- await storage ( ) . _remove ( key ( auth ) ) ;
61
+ await storage ( ) . _remove ( persistenceKey ( auth ) ) ;
62
62
}
63
63
return event ;
64
64
}
@@ -81,7 +81,7 @@ export function _eventFromPartialAndUrl(
81
81
const params = searchParamsOrEmpty ( callbackUrl ) ;
82
82
// Get the error object corresponding to the stringified error if found.
83
83
const errorObject = params [ 'firebaseError' ]
84
- ? JSON . parse ( decodeURIComponent ( params [ 'firebaseError' ] ) )
84
+ ? parseJsonOrNull ( decodeURIComponent ( params [ 'firebaseError' ] ) )
85
85
: null ;
86
86
const code = errorObject ?. [ 'code' ] ?. split ( 'auth/' ) ?. [ 1 ] ;
87
87
const error = code ? _createError ( code ) : null ;
@@ -125,10 +125,19 @@ function storage(): Persistence {
125
125
return _getInstance ( browserLocalPersistence ) ;
126
126
}
127
127
128
- function key ( auth : Auth ) : string {
128
+ function persistenceKey ( auth : Auth ) : string {
129
129
return _persistenceKeyName ( KeyName . AUTH_EVENT , auth . config . apiKey , auth . name ) ;
130
130
}
131
131
132
+
133
+ function parseJsonOrNull ( json : string ) : ReturnType < typeof JSON . parse > | null {
134
+ try {
135
+ return JSON . parse ( json ) ;
136
+ } catch ( e ) {
137
+ return null ;
138
+ }
139
+ }
140
+
132
141
// Exported for testing
133
142
export function _getDeepLinkFromCallback ( url : string ) : string {
134
143
const params = searchParamsOrEmpty ( url ) ;
0 commit comments