标签: firebase-authentication

ReactJS firebase.initializeApp 不是函数

我正在使用本教程使用 Firebase 在我的 ReactJS 应用程序中实现用户身份验证:https ://www.robinwieruch.de/complete-firebase-authentication-react-tutorial/

以前我得到了一个未定义的长度,这要归功于在初始化 firebase 时删除了对应用程序长度的检查。但是现在我现在得到 firebase.initializeApp 不是函数错误。 在此处输入图片说明

我发现的唯一其他类似错误是在 nodeJS 中,但是解决方案只是一个错字。firebase.intializeApp 不是函数

我已经删除了访问 firebase 提供的方法的所有多余步骤,现在只使用那些直接从 firebase 可用的步骤。(请参阅帖子的版本历史记录。)

我当前的代码设置如下:

注册.js

import React, { PropTypes, Component } from 'react';
import Button from 'react-bootstrap/lib/Button';
import Panel from 'react-bootstrap/lib/Panel';
import { auth } from 'firebase';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import s from './Register.css';
import history from '../../core/history';
import Background from '../login/loginBackground.jpg';

const sectionStyle = {
  width: '100%',
  height: '900px',
  backgroundImage: `url(${Background})`,
};

const title = 'Register';

const INITIAL_STATE = …
Run Code Online (Sandbox Code Playgroud)

javascript firebase reactjs firebase-authentication

0
推荐指数
1
解决办法
3365
查看次数

admin.auth().currentUser; 在 Cloud Functions 中返回 undefined

我正在尝试创建一个函数,当设备在应用程序中注册时,会将这个设备 uid 附加到注册该设备的登录用户的 uid(这是在另一个 firestore 集合中,当用户寄存器)。

这是我的代码:

exports.addDeviceToUser = functions.firestore.document('device-names/{device}').onUpdate((change, context) => {
    const currentUser = admin.auth().currentUser;
    const deviceName = context.params.device;
    var usersRef = db.collection('users');
    var queryRef = usersRef.where('uid', '==', currentUser.uid);

    if (authVar.exists) {
        return queryRef.update({sensors: deviceName}).then((writeResult => {
        return console.log('Device attached');
        }));
    } else {return console.log('Device attachment failed, user not signed in');}
});
Run Code Online (Sandbox Code Playgroud)

我一直收到此错误:“类型错误:无法读取未定义的属性 'uid'。” 显然我无法访问当前用户的身份验证信息。为什么?

javascript firebase firebase-authentication google-cloud-functions google-cloud-firestore

0
推荐指数
1
解决办法
2100
查看次数

如何从 Firebase 管理员获取 Facebook ID?

我正在使用 Firebase Admin 登录我的 NodeJs 应用程序。客户端将通过发送 idToken(从 Firebase 获取)登录,然后 NodeJs 服务器将使用 admin.auth().verifyIdToken(idToken) 获取用户。

结果将如下所示:

{ iss: 'https://securetoken.google.com/myapp-5cde1',
  name: 'Manh Hung',
  picture: 'https://graph.facebook.com/185960225411xxx/picture',
  aud: 'xxxxxx-5cde1',
  auth_time: 1526626xxx,
  user_id: 'uCxxxxxxxxxxxxxxxQR4d2',
  sub: 'uCwNoxxxxxxxxxxxxxxuQR4d2',
  iat: 15266xxx1,
  exp: 15266xxx91,
  firebase:
   { identities: { 'facebook.com': [Array] },
     sign_in_provider: 'facebook.com' },
  uid: 'uCxxxxxxxxxxxxxxxQR4d2' 
}
Run Code Online (Sandbox Code Playgroud)

是的,我通过“sign_in_provider:'facebook.com'”获得了用户的注册方法。但我不知道如何获取用户的 Facebook ID。有人可以给我建议吗?非常感谢!

javascript node.js firebase firebase-authentication

0
推荐指数
1
解决办法
1400
查看次数

Flutter/FirebaseAuth:如何在应用启动时自动登录用户?

我有以下方法来查看用户是否已经登录,在这种情况下我确实登录并且该getCurrentUser()功能有效,因为在控制台中它确实返回“USER IS NOT NULL”但主页小部件仍然为空给我“WIDGETS LIBRARY 捕获的异常”说家不能为空之类的东西。

用户API.dart

Future<FirebaseUser> getCurrentUser() async {
FirebaseUser user = await FirebaseAuth.instance.currentUser();

if (user != null) {
  return user;
} else {
  return null;
}
}
Run Code Online (Sandbox Code Playgroud)

main.dart

class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget home;

APIs().usersAPI.getCurrentUser().then((u) {
  if (u == null) {
    print('USER IS NULL');
    home = WelcomePage();
  } else {
    print('USER IS NOT NULL');
    home = FeedPage();
  }
});

return MaterialApp(
  title: "Jedi",
  debugShowCheckedModeBanner: false,
  home: home,
  routes: { …
Run Code Online (Sandbox Code Playgroud)

dart firebase firebase-authentication flutter

0
推荐指数
1
解决办法
5398
查看次数

通过电子邮件获取 uid

我在网络上使用 firebase 身份验证,我有一个与此类似的数据库:

categories: {
    c1: {
        name: "Category 1,
    },
    c2: {
        name: "Category 2,
    },
    c3: {
        name: "Category 3,
    }
}
categoryOwners: {
    //u1 and u2 are uids generated by firebase authentication
    u1: { 
        c1: true,
        c3: true
    }
    u2: {
        c1: true,
        c2: true
    }
}
Run Code Online (Sandbox Code Playgroud)

这个想法是用户可以创建新类别并与其他用户共享。

因此,用户可以创建一个类别,他将为该类别提供一个名称以及来自他想要共享该类别的人员的一系列电子邮件。

有没有办法通过前端用户提供的电子邮件从firebase身份验证中获取uid?

我的假设是,出于安全原因,我将无法在前端执行此操作,因此我必须创建一个“用户”表并对其进行维护,或者我可以创建一个云功能。

我的假设正确吗?如果是这样,您认为哪种方法会更优雅?

firebase firebase-authentication firebase-realtime-database

0
推荐指数
1
解决办法
1016
查看次数

Firebase Cloud Firestore 限制用户访问(银行应用程序)

我正在使用 firebase cloud firestore 开发银行应用程序。我已经设置了这样的规则:

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.uid != null;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我的数据库结构如下:

/consumers/{consumer_id}/transactions/{transaction_id}

{consumer_id} 将包含该消费者的帐户余额以及其他详细信息,而 {transaction_id} 将包含有关每笔交易的详细信息。

因此,如果任何经过身份验证的用户想要提款,他们可以使用 android 应用程序/Web 应用程序进行提取。问题是,同一用户是否可以在我不知情的情况下使用他们的凭据和 REST 端点访问数据库(例如:更新他们的帐户余额)?如果是这样,我如何防止他们这样做?

firebase firebase-security firebase-authentication google-cloud-firestore

0
推荐指数
1
解决办法
1479
查看次数

有没有办法从firebase身份验证中删除用户?

我正在使用 Firebase Auth Rest API。我有用 PHP 编写的代码来将用户添加到数据库和 firebase 身份验证。我存储的信息是kind、idToken、email、refreshToken、expiresIn、localId。这一切都很棒!

现在,当我尝试从数据库中删除用户时,它工作正常,但不会从 firebase 身份验证中删除用户。请在下面找到用于注册和删除用户的代码。

我得到的错误是 CREDENTIALS_TOO_OLD_LOGIN_AGAIN(或)INVALID_ID_TOKEN。

FIREBASE_KEY 是我的 firebase 密钥,在 $data 我传递用户 idToken

/*
* User Sign Up
*/

function user_signup($data){
    $response = true;
    $data = json_encode($data);

    $url = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=".FIREBASE_KEY;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    $jsonResponse = curl_exec($ch);
    if(curl_errno($ch))
    {
        $response = false;
    }
    curl_close($ch);
    return $jsonResponse;
}

/*
* User Delete
*/

/* function user_delete($data){
    $response = …
Run Code Online (Sandbox Code Playgroud)

php firebase-authentication firebase-realtime-database

0
推荐指数
1
解决办法
1766
查看次数

Firebase 函数 onCall,响应:警告,缺少 FIREBASE_CONFIG 环境变量。初始化 firebase-admin 将失败

我尝试从本地项目调用我的测试函数。

但是每次我打电话时,我都会收到 401 错误。我不知道这里有什么麻烦,在前端我有带 api 密钥的 init 应用程序,在我有 firebase 功能admin.credential.applicationDefault();我试图通过admin.credential.cer(apiConfig),但这无济于事。

我也有环境变量GOOGLE_APPLICATION_CREDENTIALS,带有我的配置路径。

依赖关系

    "firebase-admin": "~7.0.0",
    "firebase-functions": "^2.2.0",
    "firebase-functions-test": "^0.1.6",
Run Code Online (Sandbox Code Playgroud)

我的功能

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

admin.initializeApp({
    credential: admin.credential.applicationDefault(),
    databaseURL: "https://plan-list.firebaseio.com"
});

exports.createInviteUser = functions.https.onCall( (data, context)=> {

  return data;

});
Run Code Online (Sandbox Code Playgroud)

前端功能请求

 createInviteUser(email: string) {
        let inviteFunction = firebase.functions().httpsCallable('createInviteUser');

        inviteFunction(email)
            .then((result) => {
            // Read result of the Cloud Function.
           console.log(result);
        })
            .catch(err=>{
                console.log(err)
            });
    }
Run Code Online (Sandbox Code Playgroud)

另外,我怎么看我有所有必需的标题

在此处输入图片说明 这里从控制台记录

12:54:58.063 …
Run Code Online (Sandbox Code Playgroud)

firebase firebase-authentication google-cloud-functions google-cloud-firestore

0
推荐指数
1
解决办法
1944
查看次数

将 Firebase 方法转换为异步等待

我有这个 firebase 方法,它使用电子邮件和密码创建一个 firebase 用户

async register(name, email, password,type) {
    let id;
    const createUser = this.functions.httpsCallable('createUser');

    return await this.auth.createUserWithEmailAndPassword({email,password })
      .then((newUser)=>{
        id = newUser.user.uid;
        newUser.user.updateProfile({
          displayName: name
        })
      })
      .then(()=>{
        createUser({
          id:id,
          name:name,
          email:email,
          type:type
        })
      })
  }
Run Code Online (Sandbox Code Playgroud)

它还使用获取用户详细信息和用户类型的云功能将用户添加到 Firestore 集合中。

我有3个承诺(

  1. createUserWithEmail...()
  2. updateUserProfile()1
  3. createUser()

) 彼此依赖.. 如何在一个函数中使用它们?

注意functions.auth.user().onCreate()由于用户类型字段,无法使用该方法

如何在不使用 的情况下编写此方法.then()?一些用户没有出现在数据库中

javascript firebase firebase-authentication google-cloud-functions google-cloud-firestore

0
推荐指数
1
解决办法
1321
查看次数

无法解决:com.google.firebase:firebase-auth:11.0.2

我刚刚更新了sdk,google play服务和google存储库,但仍然发生了这个错误.请帮忙,我想使用电话号码整合身份验证.

SDK Manager

logcat的

Build.gradle模块:项目

    // Top-level build file where you can add configuration options common to all sub-projects/module
return
 buildscript {
    ext.kotlin_version = '1.1.3-2'
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:3.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

Build.gradle模块:App

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'


android …
Run Code Online (Sandbox Code Playgroud)

android firebase build.gradle android-gradle-plugin firebase-authentication

-1
推荐指数
1
解决办法
2206
查看次数

'codeAutoRetrievalTimeout != null': 不是真的

我一周前开始学习颤振。我正在尝试使用 Firebase_Auth 包构建身份验证系统,但遇到此错误。目标是使用firebase电话身份验证和codeAutoRetrievalTimeout自动获取短信代码。这是我的代码

登录屏幕.dart

import 'package:flutter/material.dart';
import 'package:michot_2/screens/HomeScreen.dart';
import 'package:firebase_auth/firebase_auth.dart';

class LoginScreen extends StatelessWidget {
  final _phoneController = TextEditingController();
  final _codeController = TextEditingController();

  Future<bool> loginUser(String phone, BuildContext context) async{
    FirebaseAuth _auth = FirebaseAuth.instance;

    _auth.verifyPhoneNumber(
        phoneNumber: phone,
        timeout: Duration(seconds: 60),
        verificationCompleted: (AuthCredential credential) async{
          Navigator.of(context).pop();

          UserCredential result = await _auth.signInWithCredential(credential);

          User user = result.user;

          if(user != null){
            Navigator.push(context, MaterialPageRoute(
                builder: (context) => HomeScreen(user: user,)
            ));
          }else{
            print("Error");
          }

          //This callback would gets called when verification is done …
Run Code Online (Sandbox Code Playgroud)

firebase firebase-authentication flutter

-1
推荐指数
1
解决办法
1464
查看次数

Firebase错误创建注册和登录

我已经按照本教程:

https://www.youtube.com/watch?v=OaiLpVG6Tlc

正确(或者我相信),但是我在发布时遇到了这些错误:

2016-09-07 20:36:05.520:<FIRInstanceID/WARNING>无法获取默认令牌Error Domain = com.firebase.iid Code = 6"(null)"
2016-09-07 20:36:15.743 customLogin [833 :] <FIRAnalytics/WARNING>无法获取InstanceID:Error Domain = com.firebase.iid Code = -34018"(null)"
2016-09-07 20:36:19.504:<FIRInstanceID/WARNING>无法获取默认令牌Error Domain = com.firebase.iid Code = 6"(null)"
2016-09-07 20:36:46.642:<FIRInstanceID/WARNING>无法获取默认令牌Error Domain = com.firebase.iid Code = 6"( null)"
2016-09-07 20:37:28.821:<FIRInstanceID/WARNING>无法获取默认令牌Error Domain = com.firebase.iid Code = 6"(null)"
2016-09-07 20:38:31.108 :<FIRInstanceID/WARNING>无法获取默认令牌Error Domain = com.firebase.iid Code = 6"(null)"

我怎样才能解决这个问题?

当我尝试按下我的应用程序上的登录按钮或创建帐户按钮时,我也收到此错误:

"访问钥匙串时发生错误".

ios firebase swift firebase-authentication swift2

-2
推荐指数
1
解决办法
2621
查看次数

当我们使用 Firebase for android 注册时,如何验证由 Google 验证的电子邮件 ID?

当用户SIGN-IN METHOD在 android 中使用 Firebase 电子邮件/密码注册时,我们如何验证他们的电子邮件?

java android firebase firebase-authentication

-2
推荐指数
1
解决办法
606
查看次数