phpreactjssymfonysymfony5http-token-authentication

Symfony Login Issue Using ReactJS


I have an issue with my web application and I don't know how can I fix it.

The first application is working good using default templates from Symfony. Now we need to move it on reactjs, we already have the react application working, but I have an issue with login functionality.

The reactjs application is a stand-alone application, and Symfony will be used as API, but I don't know how to change the login functionality, because after I successfully log in using email and password, $this-getUser() is not working because Symfony does not see the user, I think. I tried this but it doesn't seem to work, because I don't have the token when I try to login. From what I understood in this tutorial, if I send X-AUTH-TOKEN in every request, Symfony will know how to get user by using the token. but how can I get the token if I need to login with email and password? Can anyone help me?

security.yaml

providers:
    our_db_provider:
        entity:
            class: App\Entity\User
            property: email
           
firewalls:
    
    main:
        anonymous: ~
        form_login:
            login_path: login
            check_path: login
            
        guard:
            authenticator:
                - App\Security\LoginFormAuthenticator

Thank you


Solution

  • I think what you need in this case is to use an API authentication system like JWT and you'll be able to log in to symfony from react with an API