feat(app-switcher): централизовать ссылки приложений в portal settings
Build and Push Auth Portal Docker Image / build-and-push (push) Successful in 1m49s
Build and Push Auth Portal Docker Image / create-release (push) Skipped

Публичный GET и admin PUT/UI /admin/apps; каталог и chrome читают URL из store.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Denozordec
2026-07-18 20:59:01 +07:00
co-authored by Cursor
parent 83bfc0355d
commit 0fa4b7adea
18 changed files with 662 additions and 46 deletions
+17
View File
@@ -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
View File
@@ -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,
}
},
)
}