Skip to content

Commit b79f555

Browse files
committed
fix(app-check): token not available on new session
1 parent 0f9c445 commit b79f555

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/firebase_app_check/firebase_app_check_web/lib/firebase_app_check_web.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,19 @@ class FirebaseAppCheckWeb extends FirebaseAppCheckPlatform {
4343
ensurePluginInitialized: (firebaseApp) async {
4444
final instance =
4545
FirebaseAppCheckWeb(app: Firebase.app(firebaseApp.name));
46-
final recaptchaType = web.window.sessionStorage
46+
var recaptchaType = web.window.localStorage
4747
.getItem(_sessionKeyRecaptchaType(firebaseApp.name));
48-
final recaptchaSiteKey = web.window.sessionStorage
48+
var recaptchaSiteKey = web.window.localStorage
4949
.getItem(_sessionKeyRecaptchaSiteKey(firebaseApp.name));
50+
51+
// For backwards compatibility, with previously used session storage
52+
if (recaptchaType == null || recaptchaSiteKey == null) {
53+
recaptchaType = web.window.sessionStorage
54+
.getItem(_sessionKeyRecaptchaType(firebaseApp.name));
55+
recaptchaSiteKey = web.window.sessionStorage
56+
.getItem(_sessionKeyRecaptchaSiteKey(firebaseApp.name));
57+
}
58+
5059
if (recaptchaType != null && recaptchaSiteKey != null) {
5160
final WebProvider provider;
5261
if (recaptchaType == recaptchaTypeV3) {
@@ -125,9 +134,9 @@ class FirebaseAppCheckWeb extends FirebaseAppCheckPlatform {
125134
} else {
126135
throw Exception('Invalid web provider: $webProvider');
127136
}
128-
web.window.sessionStorage
137+
web.window.localStorage
129138
.setItem(_sessionKeyRecaptchaType(app.name), recaptchaType);
130-
web.window.sessionStorage
139+
web.window.localStorage
131140
.setItem(_sessionKeyRecaptchaSiteKey(app.name), webProvider.siteKey);
132141
}
133142

0 commit comments

Comments
 (0)