我目前正在关注Firebase的电子邮件和密码身份验证教程。
以下是使用电子邮件和密码登录的基本代码:
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.authWithPassword({
email : "bobtony@firebase.com",
password : "correcthorsebatterystaple"
}, function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});
对于我在网站上浏览的每个页面,我是否需要使用电子邮件和密码凭据重新进行身份验证才能访问数据库?
如果是这样,我如何通过网页传递email
和password
,而不会使密码容易受到暴露。
我对安全性非常陌生,不想遇到任何安全问题或数据泄漏,因此我依赖第三方服务的原因。
当您
调用以下信息时,Firebase 会在浏览器中保留身份验证状态:
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.authWithPassword({
email : "bobtony@firebase.com",
password : "correcthorsebatterystaple"
}, function(error, authData) {
if (error) {
console.error("Login Failed!", error);
}
});
若要在页面重新加载时检索持久化的身份验证状态,可以使用 onAuth()
方法:
// this will fire even if not authenticated and authData
// will be null
ref.onAuth(function(authData) {
if (authData) {
console.log(authData.uid);
}
});
就安全性而言,Firebase需要HTTPS连接,因此所有电子邮件和密码都通过网络进行加密。