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

Confusion between the username/email field in the database and the username/email field in the request (form) #514

Closed
nightwalkeryao opened this issue Dec 28, 2023 · 4 comments

Comments

@nightwalkeryao
Copy link

nightwalkeryao commented Dec 28, 2023

Fortify Version

1.19.1

Laravel Version

10.39.0

PHP Version

8.1.18

Database Driver & Version

Oracle 19.0.0

Description

I'm working on an application in Database-First mode and unfortunately, the database structure doesn't follow Laravel conventions so a lot of things have to be customised.
When customising the Fortify settings, I changed username to <my_database_username_column> and kept email to email to match the form email field in config/fortify.php but it turns out that the request validator uses the username instead of the email and so the changes to the configuration file don't produce the expected changes. According to the documentation for the username() and email() methods in src/Fortify.php, email() retrieves the name of the email/username field in the request and username(), the name of the field for authentication in the database. Digging around in the source code, I noticed that only the username() method is used (whether for the request field or the database field).

Steps To Reproduce

  1. create a fresh Laravel project with Jetstream and Inertia
  2. change the default user model to a custom one (different column name, different implementation of the Authenticatable interface)
  3. add a custom user provider for authentication and register it in the AuthServiceProvider
  4. update auth config file to use the custom user provider by default
  5. change the value of username to a custom one in fortify config file
  6. run the app and attempt to login : Request validation fails : custom_email_column: "The custom email column field is required."

Example repo: https://github.com/nightwalkeryao/bug-report/

@driesvints
Copy link
Member

When I attempt to login using your repo I don't get any exception message. I don't have any users in the database.

I don't immediately understand why there's no error message. Could you please add a test user to the DatabaseSeeder.php for me to run so I can try a real scenario?

@nightwalkeryao
Copy link
Author

Hi @driesvints, I have updated the repository (https://github.com/nightwalkeryao/bug-report/) with the user seeder. Please re-run the migrations and seed

@driesvints
Copy link
Member

I think you're confusing fortify and jetstream here. The option you modified does perfectly work with Fortify but you still need to adjust your Jetstream code to accommodate for it. Mainly the Login.vue file etc. If you need help with that please try a support channel:

@nightwalkeryao
Copy link
Author

nightwalkeryao commented Jan 5, 2024

Sure not. I tried replacing occurrences of Fortify::username() with Fortify::email() in src/Actions/AttemptToAuthenticate.php from Fortify's vendor files and it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants