0
Guys, I’m testing how firebase authentication works, I can authenticate anyway(Github, FB, Twitter, Google) but I can only use the result data on the homepage. I would like to know how I could open another tab and be able to use the return data from firebase, because the data from my result is only available on the homepage. I even try to open a tab using window.location.href but I don’t know if it is possible to pass the result data.
HTML home page(index.html)
<button id="authGitHubButton">
Log in with GitHub
</button>
Javascript
// Autenticar com GitHub
var authGitHubButton = document.getElementById('authGitHubButton');
authGitHubButton.addEventListener('click', function () {
// Providers
var provider = new firebase.auth.GithubAuthProvider();
window.location.href = "/access.html";
signIn(provider);
});
function signIn(provider) {
firebase.auth()
.signInWithPopup(provider)
.then(function (result) {
console.log(result);
var token = result.credential.accessToken;
displayName.innerText = 'Ola, ' + result.user.displayName;
photoURL.setAttribute("src", result.user.photoURL);
photoURL.style.display = 'block';
}).catch(function (error) {
console.log(error);
alert('Falha na autenticação');
});
}
HTML new tab(access.html)
<h3 id="displayName"></h3>
<img class="photoURL text-center image-responsive" id="photoURL" src=""></img>
Romulo tried to use this information, but I was unsuccessful. You could show me what my code would look like, based on the information you’ve gone through, because the ways I’ve tried, it didn’t work.
– Mário Rodeghiero
Example on Github for you to clone and run, where I changed the approach for using the Authstatechanged event. (You need to put your firebase data on
public/javascripts/firebase.js
)– Rômulo Gabriel Rodrigues
Thanks Romulus!!
– Mário Rodeghiero