쿠키로 응답 할 토큰을 생성하는 코드는 다음과 같습니다.Axios를 사용하여 쿠키 토큰을 보내는 방법은 무엇입니까?
public function authenticate(Request $request)
{
// grab credentials from the request
$credentials = ['email'=>$request->header('email'),'password'=>$request->header('password')];
try {
// attempt to verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could_not_create_token'], 500);
}
return response($token)->cookie(
'token',$token, 60
);
}
그리고 저는 이것을 처리하기 위해 액시오를 사용하고 있습니다. 내 코드는 다음과 같습니다.
axios({
method: 'post',
url: 'http://test.dev/authenticate',
headers : {
'email':'[email protected]',
'password':'secret'
},
json:true,
})
axios({
method: 'get',
url: 'http://test.dev/api/users',
json:true,
withCredentials: true
});
이제 사용자 목록을 검색하는 토큰을 보내는 방법에 문제가 있습니다. withCredentials를 추가하려고 시도했습니다. 사실이지만 운이 없습니다.
token_not_provided 응답 오류가 발생했습니다.
질문 :
- 어떻게 응답에서 쿠키 토큰의 값을 얻을?
- 권한 보유자 {토큰}을 사용하여 액시 보를 사용하여 토큰을 보내는 방법은 무엇입니까?
미리 감사드립니다.
코드 자체를 업로드하는 데 도움을 얻으려면 코드 사진을 업로드하지 마십시오! 아무도 쉽게 복사 할 수있는 코드를 다시 입력 할 시간이 없습니다. – milo526