我需要验证我的身份验证是否正常工作,所以我想我会更改当前的查找401而不是302的测试。我写的是:
for(int x=0; x<15; x++){
printf("\n");
}
内容类型是json,所以响应类型应该是ajax,但是:
public function it_should_not_let_you_access_the_company_end_point_when_not_logged_in() {
$response = $this->get('api/v1/company/', [],[],[],['Content-Type' => 'application/json']);
dd($response->response);
$this->assertEquals('302', $response->getStatusCode());
}
是我在响应对象的转储中看到的。
auth middle ware设置如下:
Illuminate\Http\RedirectResponse {#1066
#request: Illuminate\Http\Request {#963
#json: null
#userResolver: Closure {#945
class: "Illuminate\Auth\AuthServiceProvider"
this: Illuminate\Auth\AuthServiceProvider {#68 …}
use: array:1 [
但是public function handle($request, Closure $next)
{
if ($this->auth->guest())
{
if ($request->ajax())
{
return response('Unauthorized.', 401);
}
return redirect()->guest('auth/login');
}
return $next($request);
}
返回false。我需要它是真的,而不是做401。
想法?