Firebase - 郵箱認證



在本篇章中,我們將展示如何使用 Firebase 電郵/密碼認證。

建立使用者

要對使用者進行認證,我們可以使用 createUserWithEmailAndPassword(email, password) 方法。

示例

我們考慮以下示例。

var email = "myemail@email.com";
var password = "mypassword";

firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
   console.log(error.code);
   console.log(error.message);
});

我們可以檢視 Firebase 儀表板並檢視是否建立使用者。

Firebase Email Authentication User

登入

登入過程與此類似。我們使用 signInWithEmailAndPassword(email, password) 登入使用者。

示例

我們考慮以下示例。

var email = "myemail@email.com";
var password = "mypassword";

firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
   console.log(error.code);
   console.log(error.message);
});

登出

最後我們可以使用 signOut() 方法登出使用者。

示例

我們考慮以下示例。

firebase.auth().signOut().then(function() {
   console.log("Logged out!")
}, function(error) {
   console.log(error.code);
   console.log(error.message);
});
廣告
© . All rights reserved.