Skip to content

refactor: update AuthRepositoryImpl to use Firebase Firestore consistently - #1

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1776330047-firestore-auth-data-layer
Open

refactor: update AuthRepositoryImpl to use Firebase Firestore consistently#1
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1776330047-firestore-auth-data-layer

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Refactors AuthRepositoryImpl to consistently use the injected FirebaseFirestore instance and fixes several bugs in the authentication data layer.

Firestore consistency:

  • Replaced direct Firebase.firestore calls in getUserEmailByPhone() and the removed getUserById() with the injected firestore instance via a shared usersCollection field.
  • Added @Inject constructor for proper Hilt DI.
  • Removed unused imports (FirebaseAuth, SharedPreferences, Source).

Login validation (behavioral change):

  • Login now verifies the password against the Firestore password field. Previously, login succeeded for any password as long as the email existed.
  • Login now checks isActive and rejects deactivated accounts.

Bug fixes:

  • Fixed isLoggedIn() — the old let block always evaluated to true for non-blank IDs due to true being the last expression in the block regardless of the if check.
  • getCurrentUser() rewritten for clarity; removed dead getUserById() method.
  • toUser() now uses ?: "" fallbacks and a try-catch for UserRole parsing instead of !! operators that would crash on missing Firestore fields.

Review & Testing Checklist for Human

  • Password storage format: The new login compares storedPassword != password as plaintext. If passwords in Firestore are hashed/encrypted, this comparison will always fail and break login. Verify the password field format in the users collection.
  • isActive field presence: The ?: false default means users without an isActive field in Firestore will be locked out. Verify all user documents have this field set.
  • toUser() null-safety fallbacks: Confirm that returning empty strings for missing fields (instead of crashing) is acceptable behavior — this could silently hide data issues.
  • End-to-end login test: Log in with valid credentials (email and phone number paths), verify login succeeds. Attempt login with wrong password and verify "Incorrect password" error. Attempt login with a deactivated account and verify rejection.

Notes

  • Could not run an Android build locally (no Android SDK on the dev machine), so changes are not compile-verified. A CI build or local build is recommended before merging.
  • The RepositoryModule still provides AuthRepositoryImpl via @Provides; this remains compatible with the newly added @Inject constructor.

Link to Devin session: https://app.devin.ai/sessions/7d4047aa4c39448eab3973ca6b983915
Requested by: @MoaazMushatha

…ently

- Add @Inject constructor for Hilt DI support
- Use injected firestore instance via usersCollection field everywhere
  (replaced direct Firebase.firestore references)
- Add password verification in login flow
- Add account active status check in login flow
- Fix isLoggedIn() logic bug (was always returning true for non-blank IDs)
- Fix getCurrentUser() to handle missing documents with proper null checks
- Make toUser() null-safe with fallback defaults instead of !! operators
- Add safe UserRole parsing with fallback to EXECUTOR
- Remove unused getUserById() method (dead code)
- Clean up unused imports (FirebaseAuth, SharedPreferences, Source)

Co-Authored-By: moazz.m.2021 <moazz.m.2021@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant