0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00
logto/packages/core/src/routes/sign-in-settings.ts

31 lines
1.1 KiB
TypeScript
Raw Normal View History

import { ConnectorMetadata } from '@logto/connector-types';
import { getConnectorInstances } from '@/connectors';
import { findDefaultSignInExperience } from '@/queries/sign-in-experience';
import { AnonymousRouter } from './types';
export default function signInSettingsRoutes<T extends AnonymousRouter>(router: T) {
router.get('/sign-in-settings', async (ctx, next) => {
const [signInExperience, connectorInstances] = await Promise.all([
findDefaultSignInExperience(),
getConnectorInstances(),
]);
const socialConnectors = signInExperience.socialSignInConnectorTargets.reduce<
Array<ConnectorMetadata & { id: string }>
>((previous, connectorTarget) => {
const connectors = connectorInstances.filter(
({ metadata: { target }, connector: { enabled } }) => target === connectorTarget && enabled
);
return [
...previous,
...connectors.map(({ metadata, connector: { id } }) => ({ ...metadata, id })),
];
}, []);
ctx.body = { ...signInExperience, socialConnectors };
return next();
});
}