移动应用的Laravel rest api (santum)



我用LARAVEL SANCTUM创建了一个REST API。我已经在邮差上测试了api,它按预期工作,但是当移动开发人员在ionic应用程序上使用它时,它返回登录"TOKEN MISMATCH"

我的API路由

Route::post('/register', [ApiController::class, 'register']);
Route::post('/login', [ApiController::class, 'login']);

这是login的ApiController

public function login(Request $request){
$fields = $request->validate([
'email' => 'required|string|email|max:255',
'password' => 'required|string|min:8'            
]);
//validate login parameters
//check email
$user = User::where('email', $fields['email'])->first();
//check password
if(!$user || !Hash::check($fields['password'], $user->password)){
return response([
'message' => 'Invalid Credentials'
], 401);
}
$token = $user->createToken('myapptoken')->plainTextToken;
//return $user->createToken($request->device_name)->plainTextToken;
$response = [
'user' => $user,
'token' =>$token,
];
return response($response, 201);
}

端点:https://findajob.ng/api/login

电子邮件:johndeo1@gmail.com密码:12345678

这可能不是backend的问题,但另一方面,如果在postman中一切正常,您可能会尝试:

  1. configcors中的support_credentials改为true
  2. 添加withCredential头到前端

相关内容

  • 没有找到相关文章

最新更新