Home > Software design >  Symfony JSON login with email instead of username
Symfony JSON login with email instead of username

Time:05-23

I have a fresh install of Symfony 6 and trying to login with email instead of (default) username

security.yaml

providers:
  app_user_provider:
  entity:
    class: App\Entity\User
    property: email
firewalls:
  main:
    lazy: true
    provider: app_user_provider
    json_login:
      check_path: api_login

The behaviour is correct: auth mechanism is using email field in the db to do the login. The problem is that I have to pass an username parameter instead of email when I log in, otherwise I get this error: bad request Any idea how to change the config to accept email? Thanks!

CodePudding user response:

As explained there you can use this :

# config/packages/security.yaml
security:
    # ...

    firewalls:
        main:
            anonymous: true
            lazy: true
            json_login:
                check_path:    login
                username_path: email
                password_path: password
  • Related