Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit afcb58f

Browse files
committed
iOSSimulatorFlush for known iOS Simulator issue with invalid_token
1 parent 0a0ec6b commit afcb58f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,19 @@ On the simulator you may see this message if you have more than one app with the
126126

127127
```
128128
[FirebaseDatabase] Authentication failed: invalid_token (Invalid claim 'aud' in auth token.)
129+
or
130+
[FirebaseDatabase] Authentication failed: invalid_token (audience was project 'firegroceries-904d0' but should have been project 'your-firebase-project')
129131
```
130132

131133
This is [a known issue in the Firebase SDK](http://stackoverflow.com/questions/37857131/swift-firebase-database-invalid-token-error).
132-
I always use a real device to avoid this problem.
134+
I always use a real device to avoid this problem, but you can pass an 'iOSSimulatorFlush' option to init.
135+
```
136+
firebase.init({
137+
// Optionally pass in properties for database, authentication and cloud messaging,
138+
// see their respective docs and 'iOSSimulatorFlush' to flush token before init.
139+
iOSSimulatorFlush: true
140+
}).then()
141+
```
133142

134143
## Known issues on Android
135144

firebase.ios.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ firebase.init = function (arg) {
244244

245245
firebase.instance = FIRDatabase.database().reference();
246246

247+
if (arg.iOSEmulatorFlush) {
248+
try {
249+
// Attempt to sign out before initializing, useful in case previous
250+
// project token is cached which leads to following type of error:
251+
// "[FirebaseDatabase] Authentication failed: invalid_token ..."
252+
console.log('Attempting to sign out of Firebase before init');
253+
FIRAuth.auth().signOut();
254+
console.log('Sign out of Firebase successful');
255+
} catch(signOutErr) {
256+
console.log('Sign out of Firebase error: ' + signOutErr);
257+
}
258+
}
259+
247260
if (arg.onAuthStateChanged) {
248261
firebase.authStateListener = function(auth, user) {
249262
arg.onAuthStateChanged({

0 commit comments

Comments
 (0)