简体   繁体   English

将 firebase auth 添加到 firebase 云功能的适当方法是什么

[英]What is the appropriate way to add firebase auth to firebase cloud functions

I am building an app and would like to keep authentication server side using firebase functions.我正在构建一个应用程序,并希望使用 firebase 函数保持身份验证服务器端。 I have initialized the app and added all the dependencies,我已经初始化了应用程序并添加了所有依赖项,

  1. Express表达
  2. Firebase Firebase
  3. Firebase-admin Firebase管理员

I get an error "firebase.auth is not a function" when I run the auth:运行身份验证时出现错误“firebase.auth is not a function”:

firebase.auth()
.createUserWithEmailAndPassword(newUser.email, newUser.password)

I initialize my app like so:我像这样初始化我的应用程序:

const firebaseConfig = {
    ...
  };
const firebase = require('firebase/app');
firebase.initializeApp(firebaseConfig);

I have tried a ton of import options including我尝试了很多导入选项,包括

const firebase = require('firebase/app');
firebase.initializeApp(firebaseConfig);
require('firebase/auth')

which gives me same error,这给了我同样的错误,

import * as firebase from 'firebase';

Which tells me I cant import outside of a module.这告诉我我不能在模块外导入。

I have tried deleting the node modules and reinstalling, installing in order of firebase then firebase-admin.我尝试删除节点模块并重新安装,安装顺序为 firebase 然后是 firebase-admin。 I have tried all solutions I can find and noting works.我已经尝试了所有我能找到的解决方案并注意到了工作。

Please help.请帮忙。

Thanks.谢谢。

Firebase's default providers are made to be called directly from client-side code, and not from within Cloud Functions. Firebase 的默认提供程序可以直接从客户端代码调用,而不是从 Cloud Functions 中调用。

If you want to control the authentication process with your own server-side code, you'll have to have the verification of the credentials yourself, and then mint a custom token for the user.如果您想使用自己的服务器端代码控制身份验证过程,则必须自己验证凭据,然后为用户生成自定义令牌

Also see some of these top search results .另请参阅其中一些热门搜索结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM