【发布时间】:2016-11-03 16:23:45
【问题描述】:
Firebase Web SDK3 中似乎有一个确认电子邮件地址的选项,请参阅here(在链接中输入您自己的项目 ID),但我找不到有关如何使用它的文档。
有人做过吗?
【问题讨论】:
标签: javascript firebase firebase-authentication
Firebase Web SDK3 中似乎有一个确认电子邮件地址的选项,请参阅here(在链接中输入您自己的项目 ID),但我找不到有关如何使用它的文档。
有人做过吗?
【问题讨论】:
标签: javascript firebase firebase-authentication
隐藏得很好,但你去吧:https://firebase.google.com/docs/reference/js/firebase.User#sendEmailVerification
那么您只需在身份验证流程中检查emailVerified。
【讨论】:
简而言之,下面是您在 AngularJS 中的基本处理方式:
// thecontroller.js
$scope.sendVerifyEmail = function() {
console.log('Email sent, whaaaaam!');
currentAuth.sendEmailVerification();
}
// where currentAuth came from something like this:
// routerconfig
....
templateUrl: 'bla.html',
resolve: {
currentAuth:['Auth', function(Auth) {
return Auth.$requireSignIn() // this throws an AUTH_REQUIRED broadcast
}]
}
...
// intercept the broadcast like so if you want:
....
$rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {
if (error === "AUTH_REQUIRED") {
$state.go('login', { toWhere: toState });
}
});
....
// So user receives the email. How do you process the `oobCode` that returns?
// You may do something like this:
// catch the url with its mode and oobCode
.state('emailVerify', {
url: '/verify-email?mode&oobCode',
templateUrl: 'auth/verify-email.html',
controller: 'emailVerifyController',
resolve: {
currentAuth:['Auth', function(Auth) {
return Auth.$requireSignIn()
}]
}
})
// Then digest like so where each term is what they sound like:
.controller('emailVerifyController', ['$scope', '$stateParams', 'currentAuth', 'DatabaseRef',
function($scope, $stateParams, currentAuth, DatabaseRef) {
console.log(currentAuth);
$scope.doVerify = function() {
firebase.auth()
.applyActionCode($stateParams.oobCode)
.then(function(data) {
// change emailVerified for logged in User
console.log('Verification happened');
})
.catch(function(error) {
$scope.error = error.message;
console.log(error.message, error.reason)
})
};
}
])
【讨论】: