0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(core): apply account center field control

This commit is contained in:
wangsijie 2024-11-07 11:35:36 +08:00
parent 8e0d717781
commit b210d8b59c
No known key found for this signature in database
GPG key ID: F95DE0D0DDB952CF

View file

@ -0,0 +1,30 @@
import type { AccountCenter } from '@logto/schemas';
import type { MiddlewareType } from 'koa';
import { type IRouterParamContext } from 'koa-router';
import type Queries from '#src/tenants/Queries.js';
import assertThat from '../../../utils/assert-that.js';
/**
* Extend the context with the account center configs.
*/
export type WithAccountCenterContext<ContextT extends IRouterParamContext = IRouterParamContext> =
ContextT & { accountCenter: AccountCenter };
/**
* Create a middleware that injects the account center configs and ensures
* the global config is enabled.
*/
export default function koaAccountCenter<StateT, ContextT extends IRouterParamContext, ResponseT>({
accountCenters: { findDefaultAccountCenter },
}: Queries): MiddlewareType<StateT, WithAccountCenterContext<ContextT>, ResponseT> {
return async (ctx, next) => {
const accountCenter = await findDefaultAccountCenter();
assertThat(accountCenter.enabled, 'account_center.not_enabled');
ctx.accountCenter = accountCenter;
return next();
};
}