Inside loginUser function, I want to access the value of accessToken which is in side the 'stsTokenManager' but when i try to access this value then i am getting 'undefind' value.
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
// }
ponentDidMount() {
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')
}
}
Please check my loginUser function because i am able to access email and other think but when i try to access stsTokenManager then i am getting undefind value.And, I am using firebase authentication.
Inside loginUser function, I want to access the value of accessToken which is in side the 'stsTokenManager' but when i try to access this value then i am getting 'undefind' value.
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
// }
ponentDidMount() {
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')
}
}
Please check my loginUser function because i am able to access email and other think but when i try to access stsTokenManager then i am getting undefind value.And, I am using firebase authentication.
Share Improve this question edited May 31, 2018 at 10:12 Suresh Prajapati 4,5076 gold badges28 silver badges40 bronze badges asked May 31, 2018 at 9:59 suryasurya 1692 silver badges9 bronze badges 5-
Can you log to check what is
response.user
? – Suresh Prajapati Commented May 31, 2018 at 10:01 - Yes, it is return the response. – surya Commented May 31, 2018 at 10:05
-
So you mean
response.user
doesn't have keystsTokenManager
? – Suresh Prajapati Commented May 31, 2018 at 10:06 -
No,
response.user
have a keystsTokenManager
but not access. – surya Commented May 31, 2018 at 10:09 -
Can you update the question with
response
value you are getting? Seems like you may have to parse before accessing the keys – Suresh Prajapati Commented May 31, 2018 at 10:14
4 Answers
Reset to default 8response.user.toJSON().stsTokenManager
works.
response.user
doesn't have an stsTokenManager
property.
As a matter of fact, according to the documentation signInWithEmailAndPassword(email, password)
returns a firebase.Promise
containing a non-null firebase.auth.UserCredential
.
In turn, the UserCredential
contains a firebase.User
(that you get through response.user
as you did) which does not have such a stsTokenManager
property, see https://firebase.google./docs/reference/js/firebase.User
Do not depend on internal undocumented properties that are subject to change. Instead use public and official APIs that are already available. In your case, you can use response.user.getIdToken()
to get the user's ID token, this also ensures the token you get is fresh if the cached one is expired.
JSON.parse(JSON.stringify(response.user)).stsTokenManager
or
response.user.toJSON().stsTokenManager