Skip to content

Refactor sync the auth feature with the backend and client update #23

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

Conversation

fulleni
Copy link
Member

@fulleni fulleni commented Jul 5, 2025

Status

READY/IN DEVELOPMENT/HOLD

Description

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

fulleni added 6 commits July 5, 2025 17:20
This change updates the AuthenticationBloc to pass the 'isDashboardLogin: true' flag when calling the authentication repository. This aligns the dashboard with the updated HtAuthClient contract, which requires this flag to differentiate dashboard-specific login flows.
This change enhances the AuthenticationBloc by adding specific `catch` blocks for `UnauthorizedException`, `ForbiddenException`, and `NotFoundException`.

This ensures that the UI can display precise error messages to the user during the dashboard-specific authentication flow, aligning with the updated `HtAuthClient` contract.
This refactors the AppBloc's user change handler to correctly evaluate dashboard access based on the user.roles list instead of a singular role property.

The logic now checks for 'admin' or 'publisher' roles to grant authenticated status. It also corrects the condition for fetching user settings to depend on this authenticated status, not just the presence of a user object.
This refactors the AppBloc's user change handler to correctly evaluate dashboard access based on the user.roles list instead of a singular role property.

The logic now checks for 'admin' or 'publisher' roles to grant authenticated status. It also corrects the condition for fetching user settings to depend on this authenticated status, not just the presence of a user object.
This refactors the AppBloc's user change handler to correctly evaluate dashboard access based on the user.roles list instead of a singular role property.

The logic now checks for 'admin' or 'publisher' roles to grant authenticated status. It also corrects the condition for fetching user settings to depend on this authenticated status, not just the presence of a user object.
@fulleni fulleni merged commit d221b6c into main Jul 5, 2025
1 check failed
@fulleni fulleni deleted the refactor_sync_the_auth_feature_with_the_backend_and_client_update branch July 5, 2025 16:37
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @fulleni, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the application's authentication and user role management system to synchronize with recent updates in the backend and client authentication libraries. It modifies how user authentication status is determined based on their roles, updates the type handling for user roles across various configuration forms, and enhances the sign-in process with dashboard-specific logic and more granular error handling.

Highlights

  • Authentication Logic Refactor: The core application bloc (AppBloc) has been updated to determine user authentication status based on a user's roles (plural) array, specifically checking for admin or publisher roles, rather than a single role property. This aligns with a new role management approach.
  • User Role Type Migration: Throughout the AppConfigurationPage and its sub-forms, the UserRole enum has been replaced with UserRoles (likely a class containing static string constants for roles), and the userRole parameter type has been updated from UserRole to String. This change is reflected in how user preferences, ad configurations, and account actions are managed per role.
  • Enhanced Authentication Flow: The AuthenticationBloc now passes an isDashboardLogin: true flag to the authentication repository's requestSignInCode and verifySignInCode methods. New exception handling for UnauthorizedException, ForbiddenException, and NotFoundException has been added to the sign-in process.
  • Dependency Updates: The pubspec.lock file has been updated to reflect new resolved-ref hashes for several ht-auth-* and ht-shared git repositories, indicating updates to underlying authentication and shared utility libraries.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the authentication and authorization logic to align with backend changes, primarily by switching from a single user role to a list of roles. The changes correctly update how authentication status is determined in AppBloc and how role-based configurations are handled in the AppConfigurationPage. The error handling in AuthenticationBloc has also been improved with more specific exception types.

Comment on lines 76 to +81
print('Error loading user app settings: ${e.message}');
emit(state.copyWith()); // Clear settings on error
emit(state.copyWith(clearUserAppSettings: true));
} catch (e) {
// Handle any other unexpected errors
print('Unexpected error loading user app settings: $e');
emit(state.copyWith()); // Clear settings on error
emit(state.copyWith(clearUserAppSettings: true));

Choose a reason for hiding this comment

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

medium

Consider using a dedicated logging package instead of print() for more robust error handling. A logging package allows for log levels, structured formatting, and routing logs to different destinations, which is beneficial for debugging and monitoring in production environments.

Comment on lines +1062 to +1063
default:
return const SizedBox.shrink();

Choose a reason for hiding this comment

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

medium

To prevent silent failures with unhandled user roles, add an assert to the default case. This will notify developers of unhandled roles during development.

      default:
        assert(false, 'Unhandled user role in _UserPreferenceLimitsForm: ${widget.userRole}');
        return const SizedBox.shrink();

Comment on lines +1457 to 1458
default:
return const SizedBox.shrink();

Choose a reason for hiding this comment

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

medium

Add an assert to the default case to flag unhandled roles during development. This will improve code robustness and developer experience.

      default:
        assert(false, 'Unhandled user role in _AdConfigForm: ${widget.userRole}');
        return const SizedBox.shrink();

Comment on lines +1609 to 1610
default:
return const SizedBox.shrink();

Choose a reason for hiding this comment

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

medium

Add an assert to the default case to help developers catch configuration omissions for new user roles early during development.

      default:
        assert(false, 'Unhandled user role in _AccountActionConfigForm: ${widget.userRole}');
        return const SizedBox.shrink();

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