Skip to content

Commit

Permalink
add sign in with custom token in local storage function, add send sig…
Browse files Browse the repository at this point in the history
…n out message function
  • Loading branch information
fukazayo committed Jan 26, 2020
1 parent 5083237 commit eaa9e4b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ function Demo() {
this.signInCustomTokenButton.addEventListener('click', this.signInCustomToken.bind(this));
this.signOutButton.addEventListener('click', this.signOut.bind(this));
firebase.auth().onAuthStateChanged(this.onAuthStateChanged.bind(this));

// Try to sign-in with custom token in local storage.
this.signInCustomTokenInLocalStorage();
}.bind(this));
}

Expand Down Expand Up @@ -80,6 +83,16 @@ Demo.prototype.signOut = function() {
firebase.auth().signOut();
// clear the __session cookie
document.cookie = '__session=';

if (navigator.userAgent.indexOf('Android') > 0) {
// Send Signs-out message to Android
alert("signOut");
}

if (navigator.userAgent.indexOf('iPhone') > 0 || navigator.userAgent.indexOf('iPad') > 0 || navigator.userAgent.indexOf('iPod') > 0) {
// Send Signs-out message to iOS
window.webkit.messageHandlers.signOut.postMessage("");
}
};

// Does an authenticated request to a Firebase Functions endpoint using an Authorization header.
Expand Down Expand Up @@ -135,5 +148,12 @@ Demo.prototype.startFunctionsCustomTokenRequest = function() {
}.bind(this));
};

Demo.prototype.signInCustomTokenInLocalStorage = function() {
var customToken = localStorage.getItem("custom_token");
if (customToken) {
firebase.auth().signInWithCustomToken(customToken)
}
};

// Load the demo.
window.demo = new Demo();

0 comments on commit eaa9e4b

Please sign in to comment.