0

I've got an iPhone app where you create an account, and while you're logged in, you can be either active or inactive. To be clear, even when you're inactive, you're still logged in. I want to make it so that if a user is active but hasn't checked the app or used it for 45 minutes, they are automatically made inactive. Is that possible? If so, how would I go about it? I'm not trying to force a log out, but rather change their state from active to inactive. so in firebase, for each user, it has a variable for isActive. I'm trying to make it so that turns from 1 to 0 after a certain amount of idle time.

Thank you!

  • 1
    This sounds like application logic you'll have to write. Firebase doesn't provide any mechanisms to automatically alter the state of the user. (Also, Firebase Auth doesn't have a concept of "inactive" or "active".) – Doug Stevenson Feb 24 '18 at 20:24
  • Right, so in firebase, for each user, it has a variable for isActive. I'm trying to make it so that turns from 1 to 0 after a certain amount of idle time. So you're saying that if I wanted to do that, I do that in the Swift code? – Rob Haisfield Feb 24 '18 at 20:46
  • Yes, you're going to have to write code for that. – Doug Stevenson Feb 24 '18 at 20:49
  • Thank you! And does that mean the app needs to be automatically updating in the backend? – Rob Haisfield Feb 24 '18 at 20:53
  • I don't see any other way it could happen. – Doug Stevenson Feb 24 '18 at 20:55

2 Answers2

1

This can be done by leveraging a Cron Job.

There are two things that will need to happen.

You'll need determine what mechanics indicate a user is active or not. For example, every time the users taps a Search button, that timestamp is written to Firebase. As long as the difference between that time and the current time is less than 45 minutes, take no action.

A cron job to trigger code* that compares a current time stamp to the written time stamp and if greater than 45 minutes, set's the user to inactive. (actually just querying for all users where current time - posted time > 45 minutes, and set them all to inactive)

*code could be integrated with Firebase Cloud Functions, or your app could be observing a node that's set as well.

The app could also trigger this sequence but if it goes offline the active/inactive node would not be set or cleared. However, there is an onDisconnect Firebase function you may want to look into as well

We have a little app we've used to automatically log an employee out of an account if they go afk, and this design pattern works well.

Jay
  • 34,438
  • 18
  • 52
  • 81
0

Make a timer variable and make it work. Attach a mousemove event to reset the timer not stopping the timer. If the time elapsed is greater than your desired limit call the signOut method in firebase.

why mousemove? To notice the inactivity.

Actually I am a web developer most of the time dealing with javascript. I don't know which programming language you are using so use similar method as setTimeOut in javascript.