본문으로 건너뛰기

credentials()

함수 시그니처

credentials: (credentials: HTTPCredentials) => R

관련 RequestInit 속성

{
credentials: credentials
}

설명

Fetch API의 RequestInit.credentials 값을 설정합니다. 브라우저가 요청에 자격 증명 정보를 포함할지 결정할 때 사용합니다.

사용 가능한 값은 다음과 같습니다.

enum실제 값
HTTPCredentials.INCLUDE'include'
HTTPCredentials.SAME_ORIGIN'same-origin'
HTTPCredentials.OMIT'omit'

예제

import { dench, HTTPCredentials } from 'dench-fetch';

const api = dench('https://api.example.com');

const profile = await api
.get('/profile')
.credentials(HTTPCredentials.INCLUDE)
.toJson();

실제 RequestInit은 다음과 같습니다.

{
method: 'GET',
headers: {},
credentials: 'include',
}

주의사항

  • credentials: 'include'를 사용해도 서버의 CORS 및 쿠키 정책이 허용하지 않으면 자격 증명이 전송되거나 저장되지 않을 수 있습니다.
  • 현재 구현은 기존 Header를 보존하기 위해 credentials() 호출 시 headers 객체도 함께 구성합니다.