首页 > 解决方案 > 在函数外调用 var

问题描述

如何customerId在函数外部调用?

firebase.auth().onAuthStateChanged(function(user) {
    if (user) {
      var userId = firebase.auth().currentUser.uid;
      console.log("User ID:",userId);

      var database = firebase.database();
      var userId = firebase.auth().currentUser.uid;
      database.ref('stripe_customers/' + userId + '/customer_id').once('value', snapshot => {
          if (snapshot.exists()) {
             var customerId = snapshot.val();
             console.log(customerId);
          }
      });

标签: javascript

解决方案


推荐阅读