[Vuejs]-Laravel Redirect Intended does nothing

2👍

For anyone looking:

in my authenticate function:

if (Auth::attempt(['email' => $email, 'password' => $password])) {

            return response()->json([
              'response' => 'success',
              'url' => Session::get('url.intended', url('/'))
            ]);

        } else {
          return response()->json([
            'response' => 'error',
            'error' => 'Email or Password not correct.',
          ]);
        }

in my vue component login method

if(data.response == 'success'){
                    //console.log(data);
                    window.location.href = data.url
                  } else {
                    this.serverError= data.error
                  }
👤Packy

0👍

Instead of using the method intended, why not use redirect()->route() instead?

Or you are expecting a URL response. You should not use the redirect() method.

For your given code, you might want to consider this.

if (Auth::attempt(['email' => $email, 'password' => $password])) {

            return response()->json([
              'response' => 'success',
              'url' => Session::get('url.intended', route('route_of_your_dashboard'))
            ]);

        } else {
          return response()->json([
            'response' => 'error',
            'error' => 'Email or Password not correct.',
          ]);
        }

Leave a comment