我使用的是 laravel 框架版本 8.54 和 sainttum 版本 2.15
public function customerLogin(Request $request){
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|string',
]);
$customer = Customer::where('email', $request->email)->first();
if ($customer && Hash::check($request->password, $customer->password)) {
$token = $customer->createToken('Api Token for the customer')->plainTextToken;
return response()->json(['success' => true,'token' => $token]);
}
return response()->json(['success' => false, 'error' => 'Email or Password is wrong']);
}
public function AuthenticatedCustomer(){
return response()->json(['customer' => Auth::user()]);
}
'guards' => [
'customer' => [
'driver' => 'session',
'provider' => 'customers'
],
],
'providers' => [
'customers' => [
'driver' => 'eloquent',
'model' => App\Models\Customer::class,
]
]
Route::post('/login',[CustomerController::class,'customerLogin']);
Route::get('/customer',[CustomerController::class,'AuthenticatedCustomer'])->middleware('auth:sanctum');
帮我解决这个401错误
我这边的问题是请求剥夺了标头的授权