feat(app-switcher): централизовать ссылки приложений в portal settings
Публичный GET и admin PUT/UI /admin/apps; каталог и chrome читают URL из store. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -3,17 +3,20 @@ import { hash } from '@node-rs/argon2'
|
||||
import {
|
||||
createUser,
|
||||
deleteUser,
|
||||
getAppSwitcherConfig,
|
||||
getUserApps,
|
||||
getUserByEmail,
|
||||
getUserById,
|
||||
getUserPermissions,
|
||||
listUsers,
|
||||
setAppSwitcherConfig,
|
||||
setUserAccess,
|
||||
updateUser,
|
||||
} from '@authportal/db'
|
||||
import {
|
||||
APP_IDS,
|
||||
allPermissionKeys,
|
||||
appSwitcherConfigSchema,
|
||||
createUserRequestSchema,
|
||||
patchUserRequestSchema,
|
||||
putUserAccessRequestSchema,
|
||||
@@ -205,4 +208,18 @@ export async function adminRoutes(app: FastifyInstance): Promise<void> {
|
||||
return mapUser(app.db, getUserById(app.db, request.params.id)!)
|
||||
},
|
||||
)
|
||||
|
||||
app.get('/api/v1/admin/app-switcher', async () =>
|
||||
getAppSwitcherConfig(app.db),
|
||||
)
|
||||
|
||||
app.put('/api/v1/admin/app-switcher', async (request, reply) => {
|
||||
const parsed = appSwitcherConfigSchema.safeParse(request.body)
|
||||
if (!parsed.success) {
|
||||
return reply.status(400).send({
|
||||
error: { code: 'VALIDATION_ERROR', message: 'Некорректные данные' },
|
||||
})
|
||||
}
|
||||
return setAppSwitcherConfig(app.db, parsed.data)
|
||||
})
|
||||
}
|
||||
|
||||
+17
-10
@@ -1,19 +1,20 @@
|
||||
import type { FastifyInstance } from 'fastify'
|
||||
import { hash, verify } from '@node-rs/argon2'
|
||||
import { randomBytes } from 'node:crypto'
|
||||
import {
|
||||
PERMISSION_CATALOG,
|
||||
appsMetaFromSwitcher,
|
||||
loginRequestSchema,
|
||||
type LoginResponse,
|
||||
} from '@authportal/shared'
|
||||
import {
|
||||
createRefreshSession,
|
||||
getAppSwitcherConfig,
|
||||
getUserApps,
|
||||
getUserByEmail,
|
||||
getUserPermissions,
|
||||
revokeRefreshSession,
|
||||
} from '@authportal/db'
|
||||
import {
|
||||
APPS,
|
||||
PERMISSION_CATALOG,
|
||||
loginRequestSchema,
|
||||
type LoginResponse,
|
||||
} from '@authportal/shared'
|
||||
import { requireAuth, toMe } from '../plugins/auth-guards.js'
|
||||
|
||||
const REFRESH_COOKIE = 'refresh_token'
|
||||
@@ -104,6 +105,9 @@ export async function authRoutes(app: FastifyInstance): Promise<void> {
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
/** Public — apps chrome (CFDM/VPS) fetch switcher URLs without portal JWT. */
|
||||
app.get('/api/v1/app-switcher', async () => getAppSwitcherConfig(app.db))
|
||||
|
||||
app.get(
|
||||
'/api/v1/auth/me',
|
||||
{ onRequest: requireAuth },
|
||||
@@ -123,9 +127,12 @@ export async function authRoutes(app: FastifyInstance): Promise<void> {
|
||||
app.get(
|
||||
'/api/v1/catalog',
|
||||
{ onRequest: requireAuth },
|
||||
async () => ({
|
||||
apps: APPS,
|
||||
permissions: PERMISSION_CATALOG,
|
||||
}),
|
||||
async () => {
|
||||
const switcher = getAppSwitcherConfig(app.db)
|
||||
return {
|
||||
apps: appsMetaFromSwitcher(switcher),
|
||||
permissions: PERMISSION_CATALOG,
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user