Firebase 3.x - Token / Session Expiration

前端 未结 4 1639
春和景丽
春和景丽 2020-12-01 05:57

Does anyone know how long would it take for the token to expire? There no option now to set the token validity on the console.

4条回答
  •  情话喂你
    2020-12-01 06:42

    If the above answer is still confusing to you, This is what i did:

    firebase.auth().onAuthStateChanged(async user => {
        if (user) {
            const lastSignInTime = new Date(user.metadata.lastSignInTime);
            const lastSignInTimeTimeStamp = Math.round(lastSignInTime.getTime() / 1000);
            const yesterdayTimeStamp = Math.round(new Date().getTime() / 1000) - (24 * 3600);
            if(lastSignInTimeTimeStamp < yesterdayTimeStamp){
              await firebase.auth().signOut()
              this.setState({
                loggedIn: false
              });
              return false;
            }
            this.setState({
              loggedIn: true,
              user
            });
          }
        })
    
    

提交回复
热议问题