mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
fix: should return demo app data when query api (#3322)
Co-authored-by: Charles Zhao <charleszhao@silverhand.io>
This commit is contained in:
parent
1ab43e628b
commit
56ffba151b
5 changed files with 36 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
import type { User, Log } from '@logto/schemas';
|
||||
import { demoAppApplicationId } from '@logto/schemas';
|
||||
import classNames from 'classnames';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useLocation, useParams } from 'react-router-dom';
|
||||
|
@ -74,7 +75,10 @@ const AuditLogDetails = () => {
|
|||
<div className={styles.label}>{t('log_details.application')}</div>
|
||||
<div>
|
||||
{data.payload.applicationId ? (
|
||||
<ApplicationName isLink applicationId={data.payload.applicationId} />
|
||||
<ApplicationName
|
||||
isLink={data.payload.applicationId !== demoAppApplicationId}
|
||||
applicationId={data.payload.applicationId}
|
||||
/>
|
||||
) : (
|
||||
'-'
|
||||
)}
|
||||
|
|
|
@ -46,7 +46,7 @@ const buildDemoAppClientMetadata = (envSet: EnvSet): AllClientMetadata => {
|
|||
return {
|
||||
...getConstantClientMetadata(envSet, ApplicationType.SPA),
|
||||
client_id: demoAppApplicationId,
|
||||
client_name: 'Demo App',
|
||||
client_name: 'Live Preview',
|
||||
redirect_uris: urlStrings,
|
||||
post_logout_redirect_uris: urlStrings,
|
||||
};
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import { generateStandardId, buildIdGenerator } from '@logto/core-kit';
|
||||
import { defaultManagementApi, Applications } from '@logto/schemas';
|
||||
import { boolean, object, string } from 'zod';
|
||||
import {
|
||||
defaultManagementApi,
|
||||
Applications,
|
||||
demoAppApplicationId,
|
||||
buildDemoAppDataForTenant,
|
||||
} from '@logto/schemas';
|
||||
import { boolean, object, string, z } from 'zod';
|
||||
|
||||
import koaGuard from '#src/middleware/koa-guard.js';
|
||||
import koaPagination from '#src/middleware/koa-pagination.js';
|
||||
|
@ -11,7 +16,7 @@ import type { AuthedRouter, RouterInitArgs } from './types.js';
|
|||
const applicationId = buildIdGenerator(21);
|
||||
|
||||
export default function applicationRoutes<T extends AuthedRouter>(
|
||||
...[router, { queries }]: RouterInitArgs<T>
|
||||
...[router, { queries, id: tenantId }]: RouterInitArgs<T>
|
||||
) {
|
||||
const {
|
||||
deleteApplicationById,
|
||||
|
@ -65,12 +70,20 @@ export default function applicationRoutes<T extends AuthedRouter>(
|
|||
'/applications/:id',
|
||||
koaGuard({
|
||||
params: object({ id: string().min(1) }),
|
||||
response: Applications.guard.merge(z.object({ isAdmin: z.boolean() })),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { id },
|
||||
} = ctx.guard;
|
||||
|
||||
// Somethings console needs to display demo app info. Build a fixed one for it.
|
||||
if (id === demoAppApplicationId) {
|
||||
ctx.body = { ...buildDemoAppDataForTenant(tenantId), isAdmin: false };
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
const application = await findApplicationById(id);
|
||||
const applicationsRoles = await findApplicationsRolesByApplicationId(id);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<meta charset="utf-8" />
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="./apple-touch-icon.png">
|
||||
<link rel="icon" href="./favicon.ico" />
|
||||
<title>Logto Demo App</title>
|
||||
<title>Logto Live Preview</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { generateStandardId } from '@logto/core-kit';
|
||||
|
||||
import type { CreateApplication } from '../db-entries/index.js';
|
||||
import type { Application, CreateApplication } from '../db-entries/index.js';
|
||||
import { ApplicationType } from '../db-entries/index.js';
|
||||
import { adminTenantId } from './tenant.js';
|
||||
|
||||
|
@ -13,6 +13,18 @@ export const adminConsoleApplicationId = 'admin-console';
|
|||
|
||||
export const demoAppApplicationId = 'demo-app';
|
||||
|
||||
export const buildDemoAppDataForTenant = (tenantId: string): Application => ({
|
||||
tenantId,
|
||||
id: demoAppApplicationId,
|
||||
name: 'Live Preview',
|
||||
secret: '',
|
||||
description: 'Preview for Sign-in Experience.',
|
||||
type: ApplicationType.SPA,
|
||||
oidcClientMetadata: { redirectUris: [], postLogoutRedirectUris: [] },
|
||||
customClientMetadata: {},
|
||||
createdAt: 0,
|
||||
});
|
||||
|
||||
export const createDefaultAdminConsoleApplication = (): Readonly<CreateApplication> =>
|
||||
Object.freeze({
|
||||
tenantId: adminTenantId,
|
||||
|
|
Loading…
Reference in a new issue