Javascript 在访问对象的值时获取未定义的值
在loginUser函数中,我希望访问“stsTokenManager”中的accessToken值,但当我尝试访问此值时,我会得到“Unfind”值Javascript 在访问对象的值时获取未定义的值,javascript,json,firebase,react-native,firebase-authentication,Javascript,Json,Firebase,React Native,Firebase Authentication,在loginUser函数中,我希望访问“stsTokenManager”中的accessToken值,但当我尝试访问此值时,我会得到“Unfind”值 import React, { Component } from 'react'; import { StyleSheet, Text, View, Image, Button, TouchableWithoutFeedback, StatusBar, TextInput, SafeAreaView, Keyboard, TouchableOp
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
Image,
Button,
TouchableWithoutFeedback, StatusBar, TextInput,
SafeAreaView, Keyboard, TouchableOpacity,
KeyboardAvoidingView
} from 'react-native';
import { CheckBox, Item, Label, Input } from 'native-base';
import * as firebase from 'firebase';
const firebaseconfig={
apiKey: " ",
authDomain: " ",
databaseURL: " ",
projectId: " ",
storageBucket: " ",
messagingSenderId: ""
};
firebase.initializeApp(firebaseconfig);
export default class Login extends Component{
// static navigationOptions = {
// header: null
// }
componentDidMount() {
firebase.auth().onAuthStateChanged((user) => {
if (user != null) {
console.log(user)
}
})
}
loginUser = (email, password) => {
try {
firebase.auth().signInWithEmailAndPassword(email, password )
.then((response)=>{
//here i want to access values of 'stsTokenManager'
console.log(response.user.stsTokenManager);
}
}
catch (error) {
alert('Check your email or password')
}
}
请检查我的登录用户功能,因为我可以访问电子邮件和其他内容,但当我尝试访问stsTokenManager时,我会得到未查找的值。而且,我正在使用firebase身份验证。
响应。用户
没有stsTokenManager属性
事实上,根据signInWithEmailAndPassword(email,password)
返回一个firebase.Promise
包含非空firebase.auth.UserCredential
反过来,
UserCredential
包含一个firebase.User
(通过response.User
)它没有这样的stsTokenManager
属性,请参见不要依赖于可能更改的内部未记录属性。而是使用已经可用的公共和官方API。在您的情况下,可以使用response.user.getIdToken()
获取用户的ID令牌,这还可以确保在缓存的令牌过期时获取的令牌是新的。response.user.toJSON().stsTokenManager
有效
JSON.parse(JSON.stringify(response.user)).stsTokenManager
或
您可以登录以检查什么是
响应。user
?是的,它返回响应。所以您的意思是响应。user
没有键stsTokenManager
?否,响应。user
有键stsTokenManager
,但没有访问权限。您能用得到的响应
值更新问题吗?看起来您可能需要在访问密钥之前进行解析。这应该是公认的答案。它回答了任何记录了身份验证输出但无法将其所看到的内容与user.stsTokenManager
解析的内容相一致的人的原始问题。
response.user.toJSON().stsTokenManager