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

chore(mobile): refactor authentication #14322

Merged
merged 14 commits into from
Nov 26, 2024
Merged

Conversation

alextran1502
Copy link
Contributor

@alextran1502 alextran1502 commented Nov 24, 2024

Refactor authentication to follow the repository pattern, add tests

The last method in the authProvider that has not been refactored yet is saveAuthInfo, which will need subsequent PRs to refactor other modules such as user and user's preferences

@jrasm91
Copy link
Contributor

jrasm91 commented Nov 25, 2024

I looked through it briefly and it looks good overall.

Copy link
Contributor

@fyfrey fyfrey left a comment

Choose a reason for hiding this comment

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

Really good to see this :)

mobile/lib/providers/auth.provider.dart Show resolved Hide resolved
mobile/lib/providers/auth.provider.dart Show resolved Hide resolved
UserAdminResponseDto? userResponse;
UserPreferencesResponseDto? userPreferences;
try {
final responses = await Future.wait([
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer using a record here with .wait at the end and destructure it on the left side. The typing is much better.

mobile/lib/providers/auth.provider.dart Outdated Show resolved Hide resolved
Comment on lines +21 to +25
await db.assets.clear();
await db.exifInfos.clear();
await db.albums.clear();
await db.eTags.clear();
await db.users.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

These can all be done concurrently. The function can also just return this future without being async.

} catch (error, stackTrace) {
_log.severe("Error logging out", error, stackTrace);
} finally {
await clearLocalData();
Copy link
Contributor

Choose a reason for hiding this comment

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

This can throw an exception as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Throwing exception here will cause the logout timeout to not finish and prevent the app to return to the login screen. You can test this scenario by logging in an instance, then change the instance IP address and logout.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I meant that clearLocalData calls the DB, so it could also throw an exception and needs to be try/cached.

mobile/lib/services/auth.service.dart Outdated Show resolved Hide resolved
mobile/lib/services/auth.service.dart Show resolved Hide resolved
Copy link
Contributor

@zackpollard zackpollard left a comment

Choose a reason for hiding this comment

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

Some great changes, LGTM!

passwordController.text,
);

if (result.shouldChangePassword && !result.isAdmin) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why we wouldn't make them change their password even if they are an admin. If that flag is set, they should be changing their password. The server probably shouldn't even let them login which I think currently it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the remnant of good ole "SAW". Technically, when the admin user is created, the shouldChangePassword flag should be set to false for that record. It is currently set to true. So we will need to logic the server to refactor this piece

@alextran1502 alextran1502 merged commit 21f14be into main Nov 26, 2024
36 checks passed
@alextran1502 alextran1502 deleted the mobile/refactor-authentication branch November 26, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants