2022-05-18 22:24:42 -05:00
|
|
|
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(
|
2022-05-30 03:28:04 -05:00
|
|
|
({ metadata: { target }, connector: { enabled } }) => target === connectorTarget && enabled
|
2022-05-18 22:24:42 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
return [
|
|
|
|
...previous,
|
|
|
|
...connectors.map(({ metadata, connector: { id } }) => ({ ...metadata, id })),
|
|
|
|
];
|
|
|
|
}, []);
|
|
|
|
ctx.body = { ...signInExperience, socialConnectors };
|
|
|
|
|
|
|
|
return next();
|
|
|
|
});
|
|
|
|
}
|