我一直在使用 Firebase 进行身份验证,只要有两种警报方法,我就可以让它工作,如下所示:
var x;
var y;
function boo() {
if (document.getElementById('email') !== null && document.getElementById('password') !== null) {
x = document.getElementById("email").value;
y = document.getElementById('password').value;
alert(x);
alert(y);
const auth = firebase.auth();
auth.createUserWithEmailAndPassword(x, y);
} else {
...
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我删除这两种警报方法,则 Firebase 中不会发送或显示任何内容,并且我在控制台中没有看到任何错误。我希望有人知道发生了什么事,因为我不想每次有人注册时都显示电子邮件和密码。
这是 HTML:
<form class="signupForm">
<input type="email" class="inputs" onblur="validateForm()" id="email" required name="email" placeholder="Email" />
<input type="password" class="inputs" id="password" required name="password" placeholder="Password" />
<button id="btn" class="buttons" onclick="boo()">Signup</button>
</form>
Run Code Online (Sandbox Code Playgroud) 在我的 React Native 应用程序中,最初,用户将是匿名的。稍后他们将有机会使用知名用户登录,但即使没有登录,我也想在会话之间保留有关(匿名)用户的数据。我怎样才能实现这个目标?即使作为匿名用户,我应该在本地存储用户的哪些内容以及如何存储以“重新验证”她的身份?
由于 Firebase 最好仅限于经过身份验证的用户,因此我应该能够以某种方式让用户保持登录状态,即使她是匿名用户。
我知道每个用户都有一个 uid,我可以将其存储在 Firebase 之外的本地。我怎样才能实现这个目标?
我知道在这种情况下(1)firebase 会尝试保留会话,(2)我可以在本地存储凭据以便在需要时重新进行身份验证。
uidfirebase 之外每个用户的和/或凭据?这是一个反应本机应用程序。我计划使用https://invertase.io/react-native-firebase来支持 Firebase,并且更愿意使用redux-persist.
react-native firebase-authentication firebase-realtime-database redux
如何配置权限,以便用户只能读取和写入其所有者所在的文档?我的文档有一个名为所有者的顶级属性。
我阅读了这些文档
https://firebase.google.com/docs/firestore/security/secure-data?authuser=0#the_resource_variable
看起来这应该可行?
service cloud.firestore {
match /databases/{database}/documents {
match /analysis/{analysis} {
allow read, write: if request.auth.email == resource.data.owner
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用。我不断收到权限不足的错误。我需要改变什么?
更新:
阅读@Doug Stevenson 链接的文档后,我决定选择
service cloud.firestore {
match /databases/{database}/documents {
match /analysis/{analysis} {
allow read, write: if request.auth.uid == resource.data.owner_uid;
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以我的初衷是当我们进行列表操作时:
A。仅返回属于用户的文档
b.只有用户拥有的文档才能由该用户读取或写入。
有了上面的配置b.就完成了。
我该如何完成a. ?
firebase firebase-security firebase-authentication google-cloud-firestore
在 Android 应用程序中,允许用户使用 Firebase 函数使用 Linkedin 作为登录选项。用户将 linkedin 令牌发送到 firebase 函数,并因此收到AdminSdk生成的Custom token。
现在我们知道令牌可用于登录
mAuth.signInWithCustomToken(mCustomToken)。但我找不到使用自定义令牌生成AuthCredential.
有OAuthProvider类可以生成AuthCredential但重新认证失败。
getCredential(String providerId, String idToken, String accessToken)
有什么办法解决这个问题吗?
I have an React app where sport teams can sign up. A team has a coach, and that coach should be able to invite members of his team via e-mail.
I already setup the creating of team members by the coach through a form where a temporary password is set
onSubmit of the form I call
auth.createUserWithEmailAndPassword(data['email'],
generateRandomPassword())
.then(user => user.sendEmailVerification())
Run Code Online (Sandbox Code Playgroud)
This is all well and working like a charm, but I cannot seem to figure out a hack that …
javascript email-verification firebase firebase-authentication
我尝试使用以下代码进行 Firebase 电话号码身份验证:
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Firebase Phone Number Auth
</title>
</head>
<body>
Updated
<script src="https://www.gstatic.com/firebasejs/4.8.1/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyAL8dSTuXb92DWu0l78dtV4m4fC8psKeV4",
authDomain: "groupinger-users.firebaseapp.com",
databaseURL: "https://groupinger-users.firebaseio.com",
projectId: "groupinger-users",
storageBucket: "groupinger-users.appspot.com",
messagingSenderId: "432661298034"
};
firebase.initializeApp(config);
</script>
<script>
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('sign- in-button', {
'size': 'invisible',
'callback': function(response) {
// reCAPTCHA solved, allow signInWithPhoneNumber.
onSignInSubmit();
}
}); firebase.auth().signInWithPhoneNumber("+91XXXXXXXXXX", window.recaptchaVerifier)
.then((confirmationResult) => {
// At this point SMS is sent. Ask user for code.
alert('A confirmation …Run Code Online (Sandbox Code Playgroud) 所以我想尝试在登录页面上每当用户弄错时显示“无效的用户名或密码”错误消息。
我的 auth.service.ts 代码是:
signinUser(email: string, password: string) {
firebase.auth().signInWithEmailAndPassword(email, password).then(
response => {
this.router.navigate(['/recipes']);
firebase.auth().currentUser.getIdToken()
.then(
(token: string) => this.token = token
);
}
)
.catch (
error => console.log(error)
);
}
Run Code Online (Sandbox Code Playgroud)
它在我的 signupcomponent.ts 文件中实现,如下所示:
import { NgForm } from '@angular/forms';
import { Component, OnInit } from '@angular/core';
import { AuthService } from '../auth.service';
@Component({
selector: 'app-signin',
templateUrl: './signin.component.html',
styleUrls: ['./signin.component.css']
})
export class SigninComponent implements OnInit {
constructor(private authService: AuthService,) { }
ngOnInit() {
}
onSignIn(form: NgForm) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Firebase 与大多数纯 HTML/CSS/Javascript 应用程序一起使用。
我获得了以下函数来处理登录 firebase (来自他们的文档)。
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
Run Code Online (Sandbox Code Playgroud)
显然,如果有人尝试登录时发生错误,就会调用一个函数来处理错误。
我的问题是我希望在 firebase 成功登录后立即发生一些逻辑(而不仅仅是在登录失败后)。有没有办法做到这一点(例如回调)?
有没有办法在用户离线时登录?如果是这样,它是如何运作的?我想在用户连接到网络之前保持用户匿名。
我正在尝试将自定义身份验证令牌与 firestore 一起使用。我正在使用 NodeJS 使用以下代码生成令牌。
const admin = require('firebase-admin');
const serviceAccount = require('./ServiceAccountKey.json')
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
var uid = "some-uid";
var claim = {
control: true
};
admin.auth().createCustomToken(uid, true)
.then(function(customToken) {
console.log(customToken)
})
.catch(function(error) {
console.log("Error creating custom token:", error);
});
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到一个令牌。我使用该令牌并使用带有标题的https://firestore.googleapis.com/v1beta1/projects/example-project-5caa9/databases/(default)/documents/users进行尝试
授权:承载 eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGFpbXMiOnsiY29udHJvbCI6dHJ1ZX0sInVpZCI6InNvbWUTdWlkIiwiaWF0IjoxNTI4MTQ0NzY3LCJleHAiOjE1MjgxNDgzNjcsImF1 ZCI6Imh0dHBzOi8vaWRlbnRpdHl0b29sa2l0Lmdvb2dsZWFwaXMuY29tL2dvb2dsZS5pZGVudGl0eS5pZGVudGl0eXRvb2xraXQudjEuSWRlbnRpdHlUb29sa2l0IiwiaXNzIjoiZmlyZWJh c2UtYWRtaW5zZGsteG9jMDRAZXhhbXBsZS1wcm9qZWN0LTVjYWE5LmlhbS5nc2VydmljZWFjY291bnQuY29tIiwic3ViIjoiZmlyZWJhc2UtYWRtaW5zZGsteG9jMDRAZXhhbXBsZS1wcm9qZWN0LTVjYWE 5LmlhbS5nc2VydmljZWFjY291bnQuY29tIn0.Bjl6VY5CZKIPNyCayROWr_ZBSRmo11hiwtnx_cbbw2Ggk3J2x0Ml2OkpXhU-vAD6Q53fCZwGgXeCdxnsXw0lr55cJH3Q6J7gitzQoRnfJgUX 9Dv1gbI90OWashxMmxtzPIpwgSnfBv61mkdv9ZVrF8o362mQBx_LUQzvGgVPEN9_9UNCH7peOS4KYr_YRMpCQVem0XMNh9WKlyBZuScjHpY6dZZhXqOHda0W9-MNAfvQ-D0pt-osq4ty-D_WYk6Cj LNmxzvHoZeoIk1YShJM4Mpyec3lXFcCXNYG2c3_r2tskTB0LF7Fc7Bg5XuJwlrAzHrnRis6iZFCx8sqH1b-Zg
获取以下 JSON。
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": …Run Code Online (Sandbox Code Playgroud) node.js firebase firebase-authentication firebase-admin google-cloud-firestore