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

Modify error message logic #94

Closed
JamesZXCVBNM opened this issue Sep 28, 2020 · 6 comments
Closed

Modify error message logic #94

JamesZXCVBNM opened this issue Sep 28, 2020 · 6 comments

Comments

@JamesZXCVBNM
Copy link

I'm trying to rebuild a specific authentication implementation we were using in Laravel 7 with Fortify, however, there doesn't seem to be a way to modify the authorisation error message returned to the user within the Fortify::authenticateUsing() method.

For example:

$user = User::where('username', $request->username)->first();

if ($user && in_array($user->status_id, [1,2,3])) {
    if (Hash::check($request->password, $user->password)) {
        return $user;
    }
}
else {
    // custom error message here -- doesn't work
    $request->session()->flash('errors', 'Account does not exist or is inactive. Check your username.');
}

I've traced this back to the Laravel/Fortify/Actions/AttemptToAuthenticate class and the throwFailedAuthenicationException function which allows you to customise the message via the resources\lang\en\auth.php file, but there doesn't seem to be a way of modifying the logic of which message should be returned anywhere?

If I'm wrong, could the documentation be updated to show how?

@driesvints
Copy link
Member

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

@JamesZXCVBNM
Copy link
Author

JamesZXCVBNM commented Sep 28, 2020

there doesn't seem to be a way of modifying the logic of which message should be returned anywhere?

It'd be cool to get an answer? If there is a way, that's fine, I'll go seek help on StackOverflow

-- Otherwise, it's a feature request.

@JamesZXCVBNM
Copy link
Author

If there was a customisable action e.g:

Fortify::attemptToAuthenticateUsing();

that we could use in the same way as the other Actions, this would solve the problem, I think.

Again, @driesvints, this is a Feature Request

@driesvints
Copy link
Member

@JamesZXCVBNM if you want to change anything feel free to send in a pr

@JamesZXCVBNM
Copy link
Author

For anyone else who stumbles on the same problem. This might help:

if ($user && in_array($user->status_id, [1,2,3])) {
    if (Hash::check($request->password, $user->password)) {
        return $user;
    }
}
else {
    throw ValidationException::withMessages([
        Fortify::username() => "Username not found or account is inactive. Please check your username.",
    ]);
}

It'd be great if the documentation could be updated to include something like that as an example

@driesvints
Copy link
Member

@JamesZXCVBNM if you want to add something feel free to PR it 👍

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

No branches or pull requests

2 participants