标签: firebase-authentication

Swift Firebase 必须是非空字符串且不包含“.” '#' '$' '[' 或 ']'

这是我之前问题的后续。我正在尝试查看电子邮件是否已被使用。

我正在使用线路

if snapshot.hasChild(email) {
Run Code Online (Sandbox Code Playgroud)

我的数据库中有一封电子邮件 test1@test.com 当我输入该电子邮件时......当我到达“.”时 在 com 之前,应用程序崩溃并给出错误消息

Must be a non-empty string and not contain '.' '#' '$' '[' or ']'
Run Code Online (Sandbox Code Playgroud)

我看到很多关于检查用户名的帖子,但我的应用程序没有用户名,只有电子邮件。我可以使用电子邮件吗

hasChild(...) {...
Run Code Online (Sandbox Code Playgroud)

firebase swift firebase-authentication firebase-realtime-database

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

注销后,我的 firebase idToken 仍然有效吗?

我的 firebase 前端中有以下代码:

  document.querySelector('#sign-out').addEventListener('click', () => {
    firebase.auth().signOut().then(() => {
      document.location = '/sign-in';
    }, (error) => {
      console.error('Sign Out Error', error);
    });
  })
Run Code Online (Sandbox Code Playgroud)

这似乎有效。我看到网络请求成功,并且重定向到/sign-in发生。

但是,当我导航到 时/chatroom,我被视为已登录。我的 python/flask 后端在端点上具有以下代码:

@app.route("/chatroom")
def chatroom():
    if 'idToken' in request.cookies:
        id_token = request.cookies.get("idToken")
        try:
            decoded_token = auth.verify_id_token(id_token)
        except:
            print("INVALID TOKEN")
            return redirect(url_for("sign_in"))

        return render_template("chatroom.html")
    else:
        return redirect(url_for("sign_in"))
Run Code Online (Sandbox Code Playgroud)

/sign-inFirebase不是在我点击此路径时将用户重定向到,而是验证令牌是否有效,因此即使我已注销,我也可以继续。

我错过了什么?

编辑:

出于调试目的将代码更改为此:

firebase.auth().signOut().then(() => {
    firebase.auth().onAuthStateChanged((user) => {
        if (user) {
          console.log('still signed in');
        } else {
          console.log('signed out');
        }
      }); …
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-authentication

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

Firebase 处理多个自定义声明

所以我有一个用例,用户可能需要多个自定义声明,但在应用程序的不同点添加,即用户可以既是店主又是店主,或者他们可能只是店主或只是用户。

我通过文档了解到,当您分配新的自定义声明时,它会覆盖原始声明,因此我需要阅读用户当前拥有的声明。这就是我被卡住的地方......在我收到索赔后,我如何将它们重新写回给用户?

exports.onGameManagement = functions.database.ref("Core/CoreGames/{game}/teams/committee").onCreate((snapshot,context)=>{
    const position = snapshot.key;
    const uid = snapshot.val();
    const game = context.params.game;
    if(position=="gLead"||position=="depGameLead"){
        //NEEDS ADMIN RIGHTS
        //ADD TOKEN WRITE RIGHTS. - check for current claims
        admin.auth().getUser(uid).then((userRecord)=>{
            //got the users claims
            console.log(userRecord.customClaims);
            //how do i add this array of claims to the setCustomUserClaims() method?
            admin.auth().setCustomUserClaims(uid, {gameAdmin: true, userRecord.customClaims}).then(() => {
                // The new custom claims will propagate to the user's ID token the
                // next time a new one is issued.
              });
        })

    }else{

    }

}) …
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-authentication google-cloud-functions firebase-admin

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

Flutter 如何让用户保持登录状态?

我有一个颤振应用程序。即使在退出应用程序后,我也想让用户保持登录状态。我有 main.dart 文件、login.dart 和dashboard.dart。如果用户尚未登录,我希望 main.dart 重定向到 login.dart,但如果找到共享首选项值,则直接重定向到仪表板。

sharedpreferences dart firebase firebase-authentication flutter

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

Flutter 应用程序未初始化 Firebase 实例

我正在创建一个在 Firebase 中使用 Google 身份验证的 Flutter 应用程序。

用户可以使用 Google 登录,但是当用户再次启动应用程序时,我需要让用户保持登录状态。

这是我的 main.dart 代码

import 'package:flutter/material.dart';
import 'login_page.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

  final FirebaseAuth _auth = FirebaseAuth.instance;

  Future<void> _checkUserStatusGoogle() async {
    await Firebase.initializeApp();
    _auth
        .authStateChanges()
        .listen((User user) {
      if (user == null) {
        print('User is currently signed out!');
      } else {
        print('User is signed in!');
      }
    });
  }


  @override
  void initState() {

      Firebase.initializeApp().whenComplete(() {
        _checkUserStatusGoogle().then((value) {
          print('Check done done');

    });
  });
  } …
Run Code Online (Sandbox Code Playgroud)

firebase-authentication flutter

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

错误:“currentUser”不是函数或方法,无法调用

我刚刚在 Flutter 应用程序中更新了 Google Firebase Auth,因为我遇到了一些错误的 SDK 错误,但现在我得到了:

错误:“currentUser”不是函数或方法,无法调用。用户 currentFirebaseUser = await FirebaseAuth.instance.currentUser();

我查看了迁移指南并了解到 currentUser() 现在通过 currentUser getter 同步。但我不确定我现在应该如何更改我的代码来解决这个问题。

static void getCurrentUserInfo() async{

User currentFirebaseUser = await FirebaseAuth.instance.currentUser();
String userid = currentFirebaseUser.uid;

DatabaseReference userRef = FirebaseDatabase.instance.reference().child('users/$userid');
userRef.once().then((DataSnapshot snapshot){

  if(snapshot.value != null){

  }
});
Run Code Online (Sandbox Code Playgroud)

}

firebase firebase-authentication flutter flutter-web

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

sendSignInLinkToEmail 函数是否适用于 firebase 模拟器?

sendSignInLinkToEmail 函数是否适用于 firebase 模拟器?我尝试了以下代码。Firebase 托管会发送电子邮件,但 Firebase 模拟器不会。(创建和登录正在使用模拟器。)如果有人知道,请告诉我。

"firebase": "^8.1.1"

“码头工人”:“v19.03.13”

“节点(在 docker 中)”:“14-alpine”

“vue(在 docker 中)”:“^2.6.11”

sourceCode firebase.js(初始化)

import fbapp from "firebase/app"
import "firebase/auth"
const config = {
 apiKey: process.env.VUE_APP_FIB_API_KEY,
 authDomain: process.env.VUE_APP_FIB_AUTHDOMAIN,
 databaseURL: process.env.VUE_APP_FIB_FIRESTORE_URL,
 projectId: process.env.VUE_APP_FIB_PROJECT_ID,
 storageBucket: process.env.VUE_APP_FIB_STRG_BUCKET,
 messagingSenderId: process.env.VUE_APP_FIB_MSG_ID,
 corsConfiguration: [{ maxAgeSeconds: 3600 }],
 measurementId: process.env.VUE_APP_FIB_MEASUREMENT_ID,
 appId: process.env.VUE_APP_FIB_APP_ID
 }
const firebase = fbapp.initializeApp(config);

export default {
  initAuth() {
    firebase.auth().useEmulator('http://localhost:9099/')
  return auth;
}
Run Code Online (Sandbox Code Playgroud)

源代码 authMail.vue

 import Firebase from '@/firebase';
 const fb_auth = Firebase.initAuth();
 // ~~ ~~ //
 methods: {
 async …
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-tools firebase-authentication

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

在android中使用firebase手机身份验证时应用程序崩溃

这个问题与其他任何问题都不相似。我已经尝试了许多解决方案,来自App crashes with firebase phone auth在获取 firebase phone auth OTP 时出错

Android 应用程序在 firebase 电话身份验证时崩溃,但没有任何效果。

在我的颤振应用程序(android)中,我使用了 firebase 电话身份验证。当我调用 firebase 的“verifyPhoneNumber”方法发送 OTP 时,我的应用程序崩溃并退出,没有留下任何错误消息。

这是我的代码

 final FirebaseAuth _auth = FirebaseAuth.instance;
 Future sendOTP(String mobNo, BuildContext context, UserData _userData) async {
 try {
  _auth.verifyPhoneNumber(
      phoneNumber: mobNo,
      verificationCompleted: (val) {
        print("verification completed val = $val");
      },
      verificationFailed: (val) {
        print("verification failed val = $val");
      },
      codeSent: (String verificationId, [int forceResendingToken]) {
        print("code sent to $mobNo");
        Navigator.pushNamed(context, '/get_otp', arguments: {
          'verificationId': verificationId, …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-authentication flutter

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

'User' 不能分配给 FutureBuilder 中的参数类型 'Future&lt;User&gt;'

我正在尝试确定用户是否使用 FirebaseAuth.instance.currentUser 登录(Flutter Firebase),然后返回 LoginScreen 或 Dashboard,但出现错误。我试图根据 FirebaseFlutter 的说明编写代码,但那些似乎已被弃用......

  Widget build(BuildContext context) {
    return FutureBuilder<User>(
        future: FirebaseAuth.instance.currentUser,
        builder: (BuildContext context, AsyncSnapshot<User> snapshot) {
          if (snapshot.hasData) {
            User user = snapshot.data;
            /// is because there is user already logged
            return Dashboard();
          }

          /// other way there is no user logged.
          return LoginScreen();
        });
  }
Run Code Online (Sandbox Code Playgroud)

我在future: ...代表The argument type 'User' can't be assigned to the parameter type 'Future<User>'. 请有人向我解释我应该怎么做,我做错了什么?我试图在函数中传递它,()=>但它仍然不起作用......目前使用 firebase_auth: 0.20 和 firebase_core 0.7

firebase firebase-authentication flutter

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

Flutter 中具有相同 Firebase 的同一应用中的用户和卖家分开

希望你一切都好

我正在尝试从同一个应用程序制作一个应用程序,您可以是用户,也可以是卖家。在我们的例子中,卖家是一家餐馆,用户是餐馆的常客。我的问题是,如果我登录“我是餐厅登录名”,而不是用户登录名。在重新启动应用程序时自动登录并将用户带到用户主页,而不是卖家主页,因为我正在使用 auth.currentUser != null ?

然后根据身份验证状态添加主屏幕或登录屏幕,但它是通用身份验证状态。我如何让它根据登录用户的类型显示不同的主屏幕。所以我知道为什么它会把我带到用户主页 - 我设置它这样做,我如何让它带我到一个或另一个

谢谢你

dart firebase firebase-authentication flutter

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