Skip to content
Back

Best Practices for Tracking Real-Time Auth State Changes in iOS (Firebase to AppWrite Migration)

  • 0
  • Auth
  • Apple
nathan
27 Oct, 2024, 08:39

Hi everyone! I’m currently migrating my iOS app from Firebase to AppWrite - which is going to take me months. In Firebase, I used Auth.auth().addStateDidChangeListener to track real-time authentication state changes, which updated my app's state and shows the user the correct screen based on their state whenever the user logged in or out.

In AppWrite, I understand that there are Realtime subscriptions for accounts, but they only work after the user is authenticated and help with things like name change or email address change NOT the current auth state.

So we have Account.get() which returns a user if logged in, which you could use on every 'protected' page (which is the entire app) which is great but I want my AuthManager observable object to manage this for me and change my: @Published var authState = AuthState.unknown accordingly for the app to track. So, are there any best practices or recommended approaches for:

  • Tracking real-time user auth state changes in iOS using AppWrite.
  • Reducing latency or optimizing requests when periodically checking auth status.
  • Any guidance on achieving a similar auth state listener effect in AppWrite would be greatly appreciated! Thank you!

Am I better to just call Account.get() at key points in the app’s lifecycle, such as app launch, user actions, and after login or logout or is it feasible to continuously poll Account.get() to replicate this real-time auth state nature of Firebase Auth?

TL;DR
Developers are seeking advice on how to track real-time auth state changes in iOS when migrating from Firebase to AppWrite. While Realtime subscriptions in AppWrite do not directly monitor auth state changes, developers can use Account.get() to check if a user is logged in at key points in the app's lifecycle. Continuous polling of Account.get() could replicate the real-time nature of Firebase auth state tracking.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more