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

Update PrepareAuthenticatedSession.php #434

Merged
merged 1 commit into from
Dec 27, 2022
Merged

Update PrepareAuthenticatedSession.php #434

merged 1 commit into from
Dec 27, 2022

Conversation

francoism90
Copy link
Contributor

Hi,

I'm using Laravel Fortify in combination with Laravel Sanctum using API tokens.

Updated fortify.php:

'middleware' => ['api'],

I'm overwriting the authenticateUsing method:

Fortify::authenticateUsing(function (Request $request) {
            $request->validate([
                'email' => 'required|email',
                'password' => 'required',
                'device_name' => 'required',
            ]);

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

            if (! $user || ! Hash::check($request->password, $user->password)) {
                throw ValidationException::withMessages([
                    'email' => ['The provided credentials are incorrect.'],
                ]);
            }

            return $user;
        });

However it fails on PrepareAuthenticatedSession because it expects a session.
Checking if a session is used, fixes the issue and I can successfully login.

Let me know your thoughts, maybe this is not the correct solution.

@taylorotwell taylorotwell merged commit 9b2f216 into laravel:1.x Dec 27, 2022
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.

None yet

2 participants