简体   繁体   中英

How to handle refresh token with Firebase in Ionic 4?

I'm trying to implement firebase as Auth mechanism in my Ionic 4 app. I'm using this code to let the user signIn with email and password:

    loginUser(value){
   return new Promise<any>((resolve, reject) => {
     firebase.auth().signInWithEmailAndPassword(value.email, value.password)
     .then(
       res => resolve(res),
       err => reject(err))
   })
  }

Since Firebase works with accessToken that expires after 1 hour of the creation and with refreshToken to refresh the first one, I'm not sure how to move on; I mean should I save both accessToken and refreshToken in my database? How to refresh the token? Is this operation done automatically or should I do something? I'm using also a JavaEE server, which detect if the user is correctly logged with Firebase, by passing the accessToken.

should I save both accessToken and refreshToken in my database?

Instead of persisting the tokens yourself, tell Firebase where to persist the authentication information with Auth.setPersistence() . For example:

firebase.auth().setPersistence(fire.localPersistence())

Be sure to test if this is even needed though, as on most environments Firebase will automatically determine where to persist the authentication state.


How to refresh the token? Is this operation done automatically or should I do something?

The ID token is automatically refreshed by the Firebase SDK, about 55 minutes after it was created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM