0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -05:00

fix(console): set language in request header (#1485)

This commit is contained in:
Gao Sun 2022-07-08 17:33:02 +08:00 committed by GitHub
parent 800f04744d
commit f2195dd8f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@ import { t } from 'i18next';
import ky from 'ky';
import { useMemo } from 'react';
import { toast } from 'react-hot-toast';
import { useTranslation } from 'react-i18next';
export class RequestError extends Error {
status: number;
@ -34,6 +35,7 @@ type Props = {
const useApi = ({ hideErrorToast }: Props = {}) => {
const { isAuthenticated, getAccessToken } = useLogto();
const { i18n } = useTranslation();
const api = useMemo(
() =>
@ -53,12 +55,13 @@ const useApi = ({ hideErrorToast }: Props = {}) => {
if (isAuthenticated) {
const accessToken = await getAccessToken(managementResource.indicator);
request.headers.set('Authorization', `Bearer ${accessToken ?? ''}`);
request.headers.set('Accept-Language', i18n.language);
}
},
],
},
}),
[getAccessToken, isAuthenticated, hideErrorToast]
[hideErrorToast, isAuthenticated, getAccessToken, i18n.language]
);
return api;