【问题标题】:How to use Firebase email address verification如何使用 Firebase 电子邮件地址验证
【发布时间】:2016-11-03 16:23:45
【问题描述】:

Firebase Web SDK3 中似乎有一个确认电子邮件地址的选项,请参阅here(在链接中输入您自己的项目 ID),但我找不到有关如何使用它的文档。

有人做过吗?

【问题讨论】:

    标签: javascript firebase firebase-authentication


    【解决方案1】:

    隐藏得很好,但你去吧:https://firebase.google.com/docs/reference/js/firebase.User#sendEmailVerification

    那么您只需在身份验证流程中检查emailVerified

    【讨论】:

    • 这当然似乎是各种文档,所以我接受了答案。当然隐藏得很好并且“稀疏”将是另一种描述它的方式!
    【解决方案2】:

    简而言之,下面是您在 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)
            })
        };
      }
    ])
    

    Email Verification with Firebase 3.0 SDK文章中有更多解释

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 2019-09-17
      • 1970-01-01
      相关资源
      最近更新 更多