我正在开发一个混合应用,使用Ionic 3和Firebase作为认证提供者。该应用程序包含2页。登录页和主页。在登录页面上,有一个使用email+password登录用户的按钮,在主页上,另一个按钮注销了当前用户。基本上,当应用程序第一次加载时,一切都很好。但是在登录之后--然后登录--然后再登录--再次调用onAuthStateChange中的函数两次,然后三次,然后是五次,依此类推,遵循Fibonacci的系列。这是登录页面代码:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
co
在一开始安装,应用程序运行没有任何问题。
检查启动屏幕上的登录状态。
用户不登录,导航到登录屏幕。
但是当应用程序最小化,然后重新打开时,unsubscribe() is not a function错误会显示并停留在启动屏幕上。这只发生在最小化>还原,从新安装和第一次运行。
这意味着,如果我从后台杀死应用程序并打开,然后最小化,然后恢复,它的工作非常好。
下面是我从firebase文档中使用的checkLoginState函数。我不确定这是否与react-native、firebase、react-native-firebase或react-navigation有关。知
因此,我遵循了一个关于创建google登录的教程。他说,您需要使用onAuthStateChanged来收听登录/退出。我不明白的部分是当他说这个方法就像‘一个开放的订阅’,我们需要‘关闭订阅’,以防止内存泄漏。
所以在看代码之前,我无法理解的是:
为什么我们需要定义unsubscribeFromAuth;为什么我们需要将onAuthStateChanged分配给this.unsubscribeFromAuth in ComponentDidMount;为什么需要使用ComponentWillUnmount并调用unsubscribeFromAuth
class App extends Rea
我目前正在做一个使用react,redux和firebase的next.js项目。当用户进入一个需要授权的页面时,如果他们没有通过身份验证,我会使用以下代码来重定向他们。 import React from 'react';
import Router from 'next/router';
import { firebase } from '../../firebase';
import * as routes from '../../constants/routes';
const withAuthorization =
下面的代码在users/路径上附加了一个观察者,并在值发生变化时记录用户。
在firebase上,此users/树取决于当前经过身份验证的用户的访问权限。
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
... do other stuff
} else {
// No user is signed in.
... do other stuff
}
});
firebase.database().ref('users&
从“firebase/auth”导入{ getAuth,onAuthStateChanged };
const auth = getAuth();
const user = auth.currentUser;
用户返回null !!
这个不是
onAuthStateChanged(auth, (user) => {
if (user) {
// User is signed in, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/f
如何检测登录用户是一个现有的用户或一个新的用户使用防火墙的反应本机。我已经使用Google创建了身份验证,但不幸的是,我没有得到任何名为isNewUser的字段作为回报。
下面是我的密码..。
async function onGoogleButtonPress() {
// Get the users ID token
const {idToken} = await GoogleSignin.signIn();
// Create a Google credential with the token
const googleCredential = auth
我正在看这段代码:
firebase.init({
onAuthStateChanged: function(data) { // optional but useful to immediately re-logon the user when he re-visits your app
console.log(data.loggedIn ? "Logged in to firebase" : "Logged out from firebase");
if (data.loggedIn) {
console.log("u
githubLogin.addEventListener('click', () => {
var provider = new firebase.auth.GithubAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
var user = result.user;
console.log(user);
firebase.auth().onAuthStateChanged(function(us
在这个页面中,有一个代码示例,其中函数调用自己(参见下面粗体的文本) --我搞不懂这意味着什么,谁能说清楚--为什么取消订阅调用自己?
console.log('Google Auth Response', googleUser);
// We need to register an Observer on Firebase Auth to make sure auth is initialized.
var unsubscribe = firebase.auth().onAuthStateChanged((firebaseUser) => {
uns