2016-02-19 128 views
0

我目前正在从Firebase关注此Email & Password Authentication tutorial保护密码客户端Firebase

这里是电子邮件和密码登录的基本代码:

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com"); 
ref.authWithPassword({ 
    email : "[email protected]", 
    password : "correcthorsebatterystaple" 
}, function(error, authData) { 
    if (error) { 
    console.log("Login Failed!", error); 
    } else { 
    console.log("Authenticated successfully with payload:", authData); 
    } 
}); 

对于每一页我通过我的网站上浏览,我需要用电子邮件地址和密码凭据访问重新认证数据库?

如果是这样,我怎么通过emailpassword通过网页,而不会使密码容易暴露。

我对安全性很陌生,不想遇到任何安全问题或数据泄露,因此我依赖于第三方服务。

+0

我的回答有帮助吗? –

回答

2

火力地堡仍然存在的认证状态在浏览器中,当你拨打:

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com"); 
ref.authWithPassword({ 
    email : "[email protected]", 
    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连接,因此所有电子邮件和密码都将通过网络加密。