I currently have a authenticate function I hit at login from a Vue component. Right now it logs the user in but no redirect happens from the controller. I am not sure if using a Vue component is causing that. Maybe I can return the intended URL in a response if so?
public function authenticate(Request $request)
{
//Validate the login and log errors if any
$this->validate($request, [
'email' => 'required',
'password' => 'required',
]);
//if they have stuff posted get it
$email = $request->get('email');
$password = $request->get('password');
//See if they are actually a user
if (Auth::attempt(['email' => $email, 'password' => $password])) {
return redirect()->intended('/dashboard');
} else {
return response()->json([
'response' => 'error',
'error' => 'Email or Password not correct.',
]);
}
}
Login method in my login.vue component:
login(){
this.isLoading = true;
this.form.post('/login')
.then(data => {
this.isLoading = false
if(data.response == 'success'){
//Maybe get a url in the response and redirect here??
} else {
this.serverError= data.error
}
})
.catch(error => {
this.isLoading = false
})
}
Using Laravel 5.4