[英]Extend "expirationTime" in Firebase Auth "stsTokenManager" in React Native
How to extend the expirationTime in the Firestore response?如何延长 Firestore 响应中的过期时间? Here using Firestore JavaScript SDK. And need to access accessToken too in React Native mobile development.
这里使用Firestore JavaScript SDK。并且在React Native移动开发中也需要访问accessToken。
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 console.log(response)
output
Object {
"user": Object {
"stsTokenManager": Object {
"accessToken": "",
"apiKey": "",
"expirationTime": 1597168005772,
"refreshToken": "",
},
"tenantId": null,
"uid": "",
},
}
You can't change the expiration time of the provided token.您无法更改提供的令牌的到期时间。 It will expire 1 hour after the last refresh.
它将在最后一次刷新后 1 小时过期。 Then token will need to be refreshed again, and the new token will last another hour.
然后需要再次刷新token,新的token还要持续一个小时。 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. Firebase Auth SDK 将自动刷新登录用户的令牌。 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.
如果您想知道令牌何时刷新,您应该使用onIdTokenChanged为其设置一个侦听器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.