title: How to update Firebase token in Flutter application after it expires and store it?
body: <p>I have created authentication with google on first time start up of app and I have my own <code>_authenticatedUser</code> which stores user token for further requests.</p>
  
  <pre><code>final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
    final GoogleSignIn googleSignIn = GoogleSignIn();
  
    Future&lt;String&gt; signInGoogle() async {
      GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
      GoogleSignInAuthentication gsa = await googleSignInAccount.authentication;
  
      FirebaseUser user = await firebaseAuth.signInWithGoogle(
          idToken: gsa.idToken, accessToken: gsa.accessToken);
      var token = await user.getIdToken();
      _authenticatedUser = User(id: user.uid, email: user.email, token: token, photo: user.photoUrl);
      SharedPreferences prefs = await SharedPreferences.getInstance();
      prefs.setString('loggedin', 'Google');
      prefs.setString('token', token);
      prefs.setString('userEmail', user.email);
      prefs.setString('userId', user.uid);
      prefs.setString('userImage', user.photoUrl);
      return 'okay';
    }
  </code></pre>
  
  <p>I then call <code>getCurrentUser()</code> function in <code>initState()</code> to check user is there or not but when the token expires then I get faulty user with expired token.</p>
  
  <pre><code>  Future&lt;FirebaseUser&gt; getCurrentUser() async {
      FirebaseUser user = await FirebaseAuth.instance.currentUser();
  
      if (user != null) {
        print('signed in');
        SharedPreferences prefs = await SharedPreferences.getInstance();
        String token = prefs.getString('token');
        String uid = prefs.getString('userId');
        String email = prefs.getString('userEmail');
        String photo = prefs.getString('photo');
        _authenticatedUser = User(email: email, id: uid, token: token, photo: photo);
        return user;
      } else {
        print('user is null');
        return null;
      }
    }
  </code></pre>
  
  <p>Please someone explain how to fix this?</p>
  
  <p>I redirect user on the basis of return of <code>getCurrentUser</code> in main.dart file.</p>