Skip to content

Commit 8f8e625

Browse files
authored
fix(console,core): include accept-language header in cloud apis and revert #8008 (#8015)
1 parent 4127d72 commit 8f8e625

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

packages/console/src/cloud/hooks/use-cloud-api.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { conditional, trySafe } from '@silverhand/essentials';
66
import Client, { ResponseError } from '@withtyped/client';
77
import { useContext, useMemo } from 'react';
88
import { toast } from 'react-hot-toast';
9+
import { useTranslation } from 'react-i18next';
910
import { z } from 'zod';
1011

1112
import { cloudApi } from '@/consts';
@@ -41,14 +42,18 @@ type UseCloudApiProps = {
4142
export const useCloudApi = ({ hideErrorToast = false }: UseCloudApiProps = {}): Client<
4243
typeof router
4344
> => {
45+
const { i18n } = useTranslation();
4446
const { isAuthenticated, getAccessToken } = useLogto();
4547
const api = useMemo(
4648
() =>
4749
new Client<typeof router>({
4850
baseUrl: window.location.origin,
4951
headers: async () => {
5052
if (isAuthenticated) {
51-
return { Authorization: `Bearer ${(await getAccessToken(cloudApi.indicator)) ?? ''}` };
53+
return {
54+
Authorization: `Bearer ${(await getAccessToken(cloudApi.indicator)) ?? ''}`,
55+
'Accept-Language': i18n.language,
56+
};
5257
}
5358
},
5459
before: {

packages/core/src/routes/organization-invitation/index.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import {
44
OrganizationInvitations,
55
organizationInvitationEntityGuard,
66
} from '@logto/schemas';
7-
import { isObject } from '@silverhand/essentials';
87
import { z } from 'zod';
98

109
import RequestError from '#src/errors/RequestError/index.js';
1110
import koaGuard from '#src/middleware/koa-guard.js';
1211
import SchemaRouter from '#src/utils/SchemaRouter.js';
1312
import assertThat from '#src/utils/assert-that.js';
1413

15-
import koaEmailI18n from '../../middleware/koa-email-i18n.js';
1614
import { errorHandler } from '../organization/utils.js';
1715
import { type ManagementApiRouter, type RouterInitArgs } from '../types.js';
1816

@@ -96,22 +94,11 @@ export default function organizationInvitationRoutes<T extends ManagementApiRout
9694
body: sendMessagePayloadGuard,
9795
status: [204],
9896
}),
99-
koaEmailI18n(queries),
10097
async (ctx, next) => {
10198
const {
10299
params: { id },
103100
body,
104101
} = ctx.guard;
105-
// The `koaEmailI18n` properties are not available in the `SchemaRouter` context.
106-
// So we have to assert its existence here to make TypeScript happy.
107-
assertThat(
108-
'emailI18n' in ctx && isObject(ctx.emailI18n),
109-
new RequestError({
110-
status: 422,
111-
code: 'request.invalid_input',
112-
details: 'The email i18n context is missing.',
113-
})
114-
);
115102
const { invitee, organizationId, inviterId } = await invitations.findById(id);
116103

117104
const templateContext =
@@ -121,7 +108,6 @@ export default function organizationInvitationRoutes<T extends ManagementApiRout
121108
);
122109

123110
await organizationInvitations.sendEmail(invitee, {
124-
...ctx.emailI18n,
125111
...templateContext,
126112
...body,
127113
});

0 commit comments

Comments
 (0)