Reputation: 81
How to extend the expirationTime in the Firestore response? Here using Firestore JavaScript SDK. And need to access accessToken too in React Native mobile development.
import firebase from 'firebase/app';
firebase.initializeApp(firebaseConfig);
const auth = firebase.auth();
export const login = (email, password) => {
return async dispatch => {
try {
const response = await auth.signInWithEmailAndPassword(email, password);
//console.log(response);
dispatch(authenticate(response.user.uid, ""));
//console.log(response.user.stsTokenManager.expirationDate, " AAA");
const expirationDate = new Date(
new Date().getTime() + parseInt(response.user.stsTokenManager.expirationTime) * 1000
);
saveDataToStorage( response.user.uid, expirationDate);
} catch (error) {
throw new Error(error?.message || 'Authenticating user failed');
}
};
};
console.log(response)
output
Object {
"user": Object {
"stsTokenManager": Object {
"accessToken": "",
"apiKey": "",
"expirationTime": 1597168005772,
"refreshToken": "",
},
"tenantId": null,
"uid": "",
},
}
Upvotes: 0
Views: 1187
Reputation: 317958
You can't change the expiration time of the provided token. It will expire 1 hour after the last refresh. Then token will need to be refreshed again, and the new token will last another hour. There is no alternative to this - the refresh is required for security reasons.
The Firebase Auth SDK will automatically refresh the token for signed-in users. There is nothing you have to do to implement this. If you want to know when the token was refreshed, you should use onIdTokenChanged to set up a listener for that.
Upvotes: 2