@hadayat I’m confused. The response is a 204 No Content, not a 401 Unauthorized.
Feb 4, 2021
20
Level 1
Authenticating a SPA using Laravel but getting 401 unauthenticated user.
Laravel Sanctum is successfully installed and setup too.
Web.php
Route::middleware('auth:sanctum')->post('/login', 'Teacher\RegisterController@login')->name('teacher.login');
Controller.php
public function login(Request $request)
{
$credentials = [
'email' => $request['email'],
'password' => $request['password'],
];
if(Auth::attempt($credentials)){
return "Success";
}else{
return response()->json([
"error"=>"User does't exists"
]);
}
}
Login.vue
login(){
axios.get('/sanctum/csrf-cookie').then(response => {
this.form.post('/login')
.then( response => {
console.log(response);
})
.catch( error => {
console.log( error );
})
});
}
console response
{data: "", status: 204, statusText: "No Content", headers: {…}, config: {…}, …}
I am following the official doc, so Implemented everything which is needed but it still says unauthenticated, console response determines that my cookie is set. What is an error, what's going wrong
Please or to participate in this conversation.