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

iOSSimulatorFlush for known iOS Simulator issue with invalid_token #66

Merged
merged 1 commit into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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