Martin Wittick
Martin Wittick

Reputation: 503

How to auto signOut a firebase user in flutter?

I'm working on a flutter app with firebase as a backend and an authentication,
now I want the app to have a trial version where the user can signInWithGoogle and use the app with full features ( for like one hour ), and then signs out automatically after that one hour ends.

SO FAR, I accomplished the following:
1- signIn with google account.
2- add signed in user to
_trial collection with timeStamp.

Future enterTrial() async {
    final UserCredential user = await Auth.instance.googleSignInMethod();
    final User actualUser = user.user;
    try {
        //_trial is a collection for users in Trial Period
      await _trial.doc(actualUser.email).set({.   
        "name": actualUser.displayName,
        "email": actualUser.email,
        "creationDate": FieldValue.serverTimestamp(),
      });
    } catch (e) {
      print(e);
    }
  }

WHAT's LEFT:
after one hour from signIn, signOut and move user from
_trial collection to _expired collection.

so that I could check if the user is expired or not.
is there a way to automatically signOut after sometime? or to - periodically - compare creationTime with currentTime and accordingly signOut?
Thanks In Advance.

Upvotes: 1

Views: 1134

Answers (1)

Amit Singh
Amit Singh

Reputation: 743

Yes You can achive this by using background_fetch package this provide you a callback function in that function you can call your logout method.

Upvotes: 2

Related Questions