Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/Logout #204

Merged
merged 33 commits into from
Dec 11, 2024
Merged

Feat/Logout #204

merged 33 commits into from
Dec 11, 2024

Conversation

SaturneV
Copy link
Contributor

@SaturneV SaturneV commented Dec 8, 2024

Summary

This PR implements the ability to logout from an account on the application. This involves logging out of the Google Auth Service, clearing users from the user viewmodel and clearing preferences parameters.

In order to implement this feature, it was necessary to implement a function enabling a user to be set in the _user value of the user viewmodel.

The initialization of the Google Auth Service was moved to the main activity to enable its use in both the SignIn and Settings features. Additionally, the Google Auth Service class was refactored to improve usability across the project. These updates also pave the way for implementing account deletion functionality #171.

Changes

  • Implement a SetUser function in UserViewModel.kt.
  • Instantiate the Google Auth Service in MainActivity.kt.
  • Refactor the GoogleAuthService class.
  • Implement a logout function in Settings.kt.
  • Link the logout function with the UI.
  • Add the logout related string in the ressources.

Tests

  • Modify existing tests by adding a Google Auth Service mock.
  • Implement a SetUser test function in UserViewModelTest.kt.
  • Implement a new UI test in SettingsTest.kt.

Please fully test this feature with your device / emulator to make sure it works properly.

@SaturneV SaturneV added the Enhancement ✨ New feature or request label Dec 8, 2024
@SaturneV SaturneV added this to the Milestone M3 milestone Dec 8, 2024
@SaturneV SaturneV self-assigned this Dec 8, 2024
@SaturneV SaturneV linked an issue Dec 8, 2024 that may be closed by this pull request
@SaturneV SaturneV marked this pull request as ready for review December 8, 2024 21:10
# Conflicts:
#	app/src/main/java/com/android/streetworkapp/MainActivity.kt
@tercierp tercierp self-requested a review December 10, 2024 17:02
Copy link
Collaborator

@tercierp tercierp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clear code ! But there's probably a problem when the user and delog something retains with which account I previously logged. And when I relog it logs directly with the previous account without offering me a choice.

preferencesViewModel.setUid("")
preferencesViewModel.setName("")
preferencesViewModel.setScore(0)
}
Copy link
Collaborator

@tercierp tercierp Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvement: The data is removed inside the PreferencesViewModel, but when I try to re-login using the Google button, I am automatically logged in with my previous account.
After some research, I found that the Google access token needs to be revoked to fully log out the user.
This can be done using the following method:

authService.revokeAccess()

I may have done something wrong, but it's strange that I can't choose which google account to log in with. What do you think ?

For more clarity I did a small demo:

Demo GIF

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch and thanks for the video, it helped me understand the problem. In fact, the signout function of the GoogleAuthService class didn't take care of properly resetting the client, so it wasn't properly disconnected and therefore it wasn't possible to choose a Google account to log in. I've made the changes.

I'll let you test if it works on your side. Let me know if you have any other questions or suggestions.

Copy link

sonarcloud bot commented Dec 10, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
77.5% Line Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@tercierp
Copy link
Collaborator

Yes, it works now. Thank you for adding this important addon.

@tercierp tercierp merged commit aae83e3 into main Dec 11, 2024
2 of 3 checks passed
@tercierp tercierp deleted the feat/logout branch December 11, 2024 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the logout ability
2 participants