简体   繁体   English

在 Firebase 中扩展“expirationTime” 在 React Native 中验证“stsTokenManager”

[英]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.

相关问题 React Native Firebase Auth 用户是 null - React Native Firebase Auth user is null 删除 firebase 中的 auth 用户 react native - Delete auth user in firebase react native Firebase 使用 React Native 进行电话身份验证 Expo - Firebase Phone Auth with React Native Expo Getstream firebase auth react 本机文档? - Getstream firebase auth react native documentation? Firebase 身份验证对 React Native auth.tenandId 错误 - Firebase authentication on React Native auth.tenandId error 如何在 React Native 应用程序的 firebase 授权文件夹中将 UIWebView 更改为 WKWebview - How to change UIWebView to WKWebview in firebase auth folder in react native app React Native - Expo 错误 - “在‘firebase’中找不到导出‘auth’: - React Native - Expo Error - "export 'auth' was not found in 'firebase' : undefined 不是 object(评估'auth.tenanatId')在 firebase react native - undefined is not an object (evaluating 'auth.tenanatId') in firebase react native Auth state 即使在卸载并重新安装后仍然坚持 react-native(iOS)! 使用 Firebase 认证 - Auth state still persisting in react-native(iOS) even after uninstalling and reinstalling! Using Firebase Auth firebase auth: TypeError: (0, _reactNative.getReactNativePersistence) 不是 function。react-native EXPO - firebase auth: TypeError: (0, _reactNative.getReactNativePersistence) is not a function. react-native EXPO
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM