mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
31 lines
1 KiB
TypeScript
31 lines
1 KiB
TypeScript
|
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 } }) => target === connectorTarget
|
||
|
);
|
||
|
|
||
|
return [
|
||
|
...previous,
|
||
|
...connectors.map(({ metadata, connector: { id } }) => ({ ...metadata, id })),
|
||
|
];
|
||
|
}, []);
|
||
|
ctx.body = { ...signInExperience, socialConnectors };
|
||
|
|
||
|
return next();
|
||
|
});
|
||
|
}
|