mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
refactor(core): fix etag
This commit is contained in:
parent
2747a1064e
commit
07e04eac55
1 changed files with 48 additions and 42 deletions
|
@ -17,51 +17,57 @@ export default function wellKnownRoutes<T extends AnonymousRouter>(
|
||||||
} = libraries;
|
} = libraries;
|
||||||
|
|
||||||
if (id === adminTenantId) {
|
if (id === adminTenantId) {
|
||||||
router.get('/.well-known/endpoints/:tenantId', async (ctx, next) => {
|
router.get(
|
||||||
if (!ctx.params.tenantId) {
|
'/.well-known/endpoints/:tenantId',
|
||||||
throw new RequestError('request.invalid_input');
|
async (ctx, next) => {
|
||||||
}
|
if (!ctx.params.tenantId) {
|
||||||
|
throw new RequestError('request.invalid_input');
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.body = {
|
||||||
|
user: getTenantEndpoint(ctx.params.tenantId, EnvSet.values),
|
||||||
|
};
|
||||||
|
|
||||||
|
return next();
|
||||||
|
},
|
||||||
|
koaBodyEtag()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/.well-known/sign-in-exp',
|
||||||
|
async (ctx, next) => {
|
||||||
|
const [signInExperience, logtoConnectors] = await Promise.all([
|
||||||
|
getSignInExperience(),
|
||||||
|
getLogtoConnectors(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const forgotPassword = {
|
||||||
|
phone: logtoConnectors.some(({ type }) => type === ConnectorType.Sms),
|
||||||
|
email: logtoConnectors.some(({ type }) => type === ConnectorType.Email),
|
||||||
|
};
|
||||||
|
|
||||||
|
const socialConnectors = signInExperience.socialSignInConnectorTargets.reduce<
|
||||||
|
Array<ConnectorMetadata & { id: string }>
|
||||||
|
>((previous, connectorTarget) => {
|
||||||
|
const connectors = logtoConnectors.filter(
|
||||||
|
({ metadata: { target } }) => target === connectorTarget
|
||||||
|
);
|
||||||
|
|
||||||
|
return [
|
||||||
|
...previous,
|
||||||
|
...connectors.map(({ metadata, dbEntry: { id } }) => ({ ...metadata, id })),
|
||||||
|
];
|
||||||
|
}, []);
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
user: getTenantEndpoint(ctx.params.tenantId, EnvSet.values),
|
...signInExperience,
|
||||||
|
socialConnectors,
|
||||||
|
forgotPassword,
|
||||||
};
|
};
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
});
|
},
|
||||||
}
|
koaBodyEtag()
|
||||||
|
);
|
||||||
router.get('/.well-known/sign-in-exp', async (ctx, next) => {
|
|
||||||
const [signInExperience, logtoConnectors] = await Promise.all([
|
|
||||||
getSignInExperience(),
|
|
||||||
getLogtoConnectors(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const forgotPassword = {
|
|
||||||
phone: logtoConnectors.some(({ type }) => type === ConnectorType.Sms),
|
|
||||||
email: logtoConnectors.some(({ type }) => type === ConnectorType.Email),
|
|
||||||
};
|
|
||||||
|
|
||||||
const socialConnectors = signInExperience.socialSignInConnectorTargets.reduce<
|
|
||||||
Array<ConnectorMetadata & { id: string }>
|
|
||||||
>((previous, connectorTarget) => {
|
|
||||||
const connectors = logtoConnectors.filter(
|
|
||||||
({ metadata: { target } }) => target === connectorTarget
|
|
||||||
);
|
|
||||||
|
|
||||||
return [
|
|
||||||
...previous,
|
|
||||||
...connectors.map(({ metadata, dbEntry: { id } }) => ({ ...metadata, id })),
|
|
||||||
];
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
ctx.body = {
|
|
||||||
...signInExperience,
|
|
||||||
socialConnectors,
|
|
||||||
forgotPassword,
|
|
||||||
};
|
|
||||||
|
|
||||||
return next();
|
|
||||||
});
|
|
||||||
|
|
||||||
router.use(koaBodyEtag());
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue