Slide 41
Slide 41 text
customFetch: Web
版 ─ SigV4
署名 + Cookie
認証
// packages/frontend/app/custom-fetch.ts(実際のコード)
export const customFetch = async (
url: string,
options: CustomFetchOptions,
): Promise => {
// AWS SigV4で署名(リージョン: ap-northeast-1, サービス: execute-api)
const signedHeaders = await getSignedHeaders(url, options.method, options.body);
// Cognito JWT をヘッダに追加(ID Pool → User Pool のフォールバック)
const cognitoJwt = await getCognitoUserPoolJwtToken();
if (cognitoJwt) {
signedHeaders["X-Cognito-Jwt"] = cognitoJwt;
}
const response = await fetch(url, {
...options,
headers: { ...options.headers, ...signedHeaders },
});
return getBody(response);
};
Orval
生成コードからはこのcustomFetch
が呼ばれる → 認証を意識しない
© MOSH, Inc.