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:
parent
800f04744d
commit
f2195dd8f3
1 changed files with 4 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue