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(dart_frog_auth): Allow users to customize their response when unauthenticated. #1631

Open
4 tasks
mtwichel opened this issue Dec 18, 2024 · 0 comments · May be fixed by #1632
Open
4 tasks

feat(dart_frog_auth): Allow users to customize their response when unauthenticated. #1631

mtwichel opened this issue Dec 18, 2024 · 0 comments · May be fixed by #1632
Labels
feature A new feature or request

Comments

@mtwichel
Copy link
Contributor

mtwichel commented Dec 18, 2024

Description

Currently, when not authenticated, the middleware in dart_frog_auth sends a response that has an empty body and status code 403. However, in applications like web sites, this is not ideal. Typically you would want to respond with an html body that informs the user they aren't logged in.

I propose adding an optional parameter to all the middleware called unauthenticatedResponse that takes a Handler?. If nothing is passed to the parameter, then it will use the existing default. If a function is passed, it will be returned if the request is not authenticated.

basicAuthentication<User>(
    unauthenticatedResponse: (context) => Response(body: /** HTML body */, status: HttpStatus.unauthenticated),
    authenticator: (context, username, password) {
        final userRepository = context.read<UserRepository>();
        return userRepository.fetchFromCredentials(username, password);
    },
)

Requirements

  • All CI/CD checks are passing.
  • There is no drop in the test coverage percentage.
  • The unauthenticatedResponse parameter exists on all the middleware
  • The change is documented in the Dart Frog docs in the authentication page

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature or request
Projects
Status: Needs Triage
Development

Successfully merging a pull request may close this issue.

1 participant