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

Commit

Permalink
Merge pull request #66 from willhlaw/signOut-option
Browse files Browse the repository at this point in the history
iOSSimulatorFlush for known iOS Simulator issue with invalid_token
  • Loading branch information
EddyVerbruggen authored Jul 5, 2016
2 parents 6e48b32 + da673e3 commit 69bfd2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,19 @@ On the simulator you may see this message if you have more than one app with the

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

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

## Known issues on Android

Expand Down
13 changes: 13 additions & 0 deletions firebase.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ firebase.init = function (arg) {

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

if (arg.iOSEmulatorFlush) {
try {
// Attempt to sign out before initializing, useful in case previous
// project token is cached which leads to following type of error:
// "[FirebaseDatabase] Authentication failed: invalid_token ..."
console.log('Attempting to sign out of Firebase before init');
FIRAuth.auth().signOut();
console.log('Sign out of Firebase successful');
} catch(signOutErr) {
console.log('Sign out of Firebase error: ' + signOutErr);
}
}

if (arg.onAuthStateChanged) {
firebase.authStateListener = function(auth, user) {
arg.onAuthStateChanged({
Expand Down

0 comments on commit 69bfd2a

Please sign in to comment.