简体   繁体   English

React-Native-Firebase Spread auth().currentUser Object {...auth().currentUser}

[英]React-Native-Firebase Spread auth().currentUser Object {...auth().currentUser}

when I Console.Log(auth().currentUser) i get the following result:当我Console.Log(auth().currentUser)我得到以下结果:

Object {
  "displayName": "Test",
  "email": "test@gmail.com",
  "emailVerified": false,
  "isAnonymous": false,
  "metadata": Object {
    "creationTime": 1638471731312,
    "lastSignInTime": 1648765363821,
  },
  "phoneNumber": null,
  "photoURL": "www.google.com",
  "providerData": Array [
    Object {
      "displayName": "Test",
      "email": "test@gmail.com",
      "photoURL": "www.google.com",
      "providerId": "password",
      "uid": "test@gmail.com",
    },
  ],
  "providerId": "firebase",
  "refreshToken": "...",
  "tenantId": null,
  "uid": "...",
}

When I Console.Log({...auth().currentUser}) I expect the same result.当我Console.Log({...auth().currentUser})我期望相同的结果。 Instead I get the following:相反,我得到以下信息:

Object {
"_auth": FirebaseAuthModule {
  "_app": FirebaseApp {
    "_automaticDataCollectionEnabled": true,
    "_deleteApp": [Function bound deleteApp],
    "_deleted": false,
    "_initialized": true,
    "_name": "[DEFAULT]",
    "_nativeInitialized": true,
    "_options": Object {
      "apiKey": "...",
      "appId": "...",
      "clientId": "...",
      "databaseURL": "...",
      "messagingSenderId": "...",
      "projectId": "...",
      "storageBucket": "...",
    },
  },
  "_authResult": true,
  "_config": Object {
    "ModuleClass": [Function FirebaseAuthModule],
    "hasCustomUrlOrRegionSupport": false,
    "hasMultiAppSupport": true,
    "namespace": "auth",
    "nativeEvents": Array [
      "auth_state_changed",
      "auth_id_token_changed",
      "phone_auth_state_changed",
    ],
    "nativeModuleName": "RNFBAuthModule",
    "statics": Object {
      "AppleAuthProvider": [Function AppleAuthProvider],
      "EmailAuthProvider": [Function EmailAuthProvider],
      "FacebookAuthProvider": [Function FacebookAuthProvider],
      "GithubAuthProvider": [Function GithubAuthProvider],
      "GoogleAuthProvider": [Function GoogleAuthProvider],
      "OAuthProvider": [Function OAuthProvider],
      "PhoneAuthProvider": [Function PhoneAuthProvider],
      "PhoneAuthState": Object {
        "AUTO_VERIFIED": "verified",
        "AUTO_VERIFY_TIMEOUT": "timeout",
        "CODE_SENT": "sent",
        "ERROR": "error",
      },
      "TwitterAuthProvider": [Function TwitterAuthProvider],
    },
    "version": "14.7.0",
  },
  "_customUrlOrRegion": undefined,
  "_languageCode": undefined,
  "_nativeModule": Object {
    "APP_LANGUAGE": Object {},
    "APP_USER": Object {
      "[DEFAULT]": Object {
        "displayName": "Test",
        "email": "test@gmail.com",
        "emailVerified": false,
        "isAnonymous": false,
        "metadata": Object {
          "creationTime": 1638471731312,
          "lastSignInTime": 1648765363821,
        },
        "phoneNumber": null,
        "photoURL": "www.google.com",
        "providerData": Array [
          Object {
            "displayName": "Test",
            "email": "test@gmail.com",
            "photoURL": "www.google.com",
            "providerId": "password",
            "uid": "test@gmail.com",
          },
        ],
        "providerId": "firebase",
        "refreshToken": "...",
        "tenantId": null,
        "uid": "...",
      },
    },
    "addAuthStateListener": [Function anonymous],
    "addIdTokenListener": [Function anonymous],
    "applyActionCode": [Function anonymous],
    "checkActionCode": [Function anonymous],
    "confirmPasswordReset": [Function anonymous],
    "confirmationResultConfirm": [Function anonymous],
    "createUserWithEmailAndPassword": [Function anonymous],
    "delete": [Function anonymous],
    "fetchSignInMethodsForEmail": [Function anonymous],
    "getConstants": [Function anonymous],
    "getIdToken": [Function anonymous],
    "getIdTokenResult": [Function anonymous],
    "linkWithCredential": [Function anonymous],
    "reauthenticateWithCredential": [Function anonymous],
    "reload": [Function anonymous],
    "removeAuthStateListener": [Function anonymous],
    "removeIdTokenListener": [Function anonymous],
    "sendEmailVerification": [Function anonymous],
    "sendPasswordResetEmail": [Function anonymous],
    "sendSignInLinkToEmail": [Function anonymous],
    "setAppVerificationDisabledForTesting": [Function anonymous],
    "setLanguageCode": [Function anonymous],
    "setTenantId": [Function anonymous],
    "signInAnonymously": [Function anonymous],
    "signInWithCredential": [Function anonymous],
    "signInWithCustomToken": [Function anonymous],
    "signInWithEmailAndPassword": [Function anonymous],
    "signInWithEmailLink": [Function anonymous],
    "signInWithPhoneNumber": [Function anonymous],
    "signOut": [Function anonymous],
    "unlink": [Function anonymous],
    "updateEmail": [Function anonymous],
    "updatePassword": [Function anonymous],
    "updatePhoneNumber": [Function anonymous],
    "updateProfile": [Function anonymous],
    "useDeviceLanguage": [Function anonymous],
    "useEmulator": [Function anonymous],
    "useUserAccessGroup": [Function anonymous],
    "verifyBeforeUpdateEmail": [Function anonymous],
    "verifyPasswordResetCode": [Function anonymous],
    "verifyPhoneNumber": [Function anonymous],
  },
  "_settings": null,
  "_tenantId": null,
  "_user": Object {
    "displayName": "Test",
    "email": "test@gmail.com",
    "emailVerified": false,
    "isAnonymous": false,
    "metadata": Object {
      "creationTime": 1638471731312,
      "lastSignInTime": 1648765363821,
    },
    "phoneNumber": null,
    "photoURL": "www.google.com",
    "providerData": Array [
      Object {
        "displayName": "Test",
        "email": "test@gmail.com",
        "photoURL": "www.google.com",
        "providerId": "password",
        "uid": "test@gmail.com",
      },
    ],
    "providerId": "firebase",
    "refreshToken": "...",
    "tenantId": null,
    "uid": "...",
  },
},
"_user": Object {
  "displayName": "Test",
  "email": "test@gmail.com",
  "emailVerified": false,
  "isAnonymous": false,
  "metadata": Object {
    "creationTime": 1638471731312,
    "lastSignInTime": 1648765363821,
  },
  "phoneNumber": null,
  "photoURL": "www.google.com",
  "providerData": Array [
    Object {
      "displayName": "Test",
      "email": "test@gmail.com",
      "photoURL": "www.google.com",
      "providerId": "password",
      "uid": "test@gmail.com",
    },
  ],
  "providerId": "firebase",
  "refreshToken": "...",
  "tenantId": null,
  "uid": "...",
},

Is this the expected behaviour?这是预期的行为吗? Why is this happening?为什么会这样? The spread operator should clone the object passed into it, shouldn't it?传播运算符应该克隆传递给它的 object,不是吗?

Like this:像这样:

let obj1 = { foo: 'bar', x: 42 };
let obj2 = { foo: 'baz', y: 13 };

let clonedObj = { ...obj1 };
// Object { foo: "bar", x: 42 }
let mergedObj = { ...obj1, ...obj2 };
// Object { foo: "baz", x: 42, y: 13 }

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

The auth().currentUser is actually a User account object that has many properties and methods in it. auth().currentUser实际上是一个用户帐户object,其中包含许多属性和方法。

From MDN ,来自MDN

The spread operator copies own enumerable properties from a provided object onto a new object.传播运算符将自己的可枚举属性从提供的 object 复制到新的 object 上。

You can use .toJSON() to get a JSON-serializable representation of this user account object.您可以使用.toJSON()获取此用户帐户 object 的JSON 可序列化表示。

console.log({ ...auth().currentUser.toJSON() })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM