Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

superfive33's avatar

Problems when sending ajax request

Hi,

I'm building an app using Laravel, VueJS and Axios in a Single Page Application. I'm using the original bootstrapping which adds the CSRF token to all my Ajax requests sent with axios.

I'm trying to setup the Authentication process through Ajax requests sent from my VueJS components (for the Sign Up form, the lost password form. I'm not working on the sign In process yet). I've extended the default Controllers so they return JSON instead of redirections.

Everything works fine for the Sign Up flow, but curiously when I send a POST request using Axios to the ForgotPasswordController Laravel Controller I get a 302 Found response code and then a redirection to /home, instead of a 2OO response code with the JSON response. I noticed that if I remove the $this->middleware('guest') from the controller's constructor, it works.

I have two questions !

  • Why is it working when sending a POST request to the /register route, and not working on the /password/email route ? In both cases I send a POST request with the same headers (including the CSRF token) to controllers which use the Guest middleware.
  • Why is it working when I remove the guest middleware from the ForgotPasswordController ?

thank you !

0 likes
2 replies
Jaytee's avatar

Forgotting a password, usually means that you can't login to your account right?

So if you're authenticated, then of course you'll be redirected as you haven't forgot your password.

If you want to add the ability to allow a signed in user to change their password, you'll need to add that manually.

superfive33's avatar

Yes thank you ! Indeed I've just noticed that I want authenticated when trying to do these requests.

Shame on me.

Please or to participate in this conversation.