refactor(split): make the app self-hosting ready

Remove the transitional website auth, admin hooks, SEO and hosted analytics together, then align the app routes, runtime configuration, tests and dependencies. These changes form one atomic cleanup because the filtered app must switch its identity and runtime surfaces as a unit.
This commit is contained in:
itsrubberduck
2026-07-27 19:17:27 +02:00
parent 3ed3865ebb
commit c8c2365c4d
29 changed files with 123 additions and 2038 deletions

View File

@@ -1,7 +1,6 @@
import { getHeader, type H3Event } from 'h3'
import mongoose from 'mongoose'
import { AppUser, type AppUserDocument } from '../models/AppUser'
import { mirrorAppUser } from './authMode'
export function normalizeBridgeToken(input: unknown) {
if (typeof input !== 'string') {
@@ -21,18 +20,7 @@ export function getBridgeTokenFromHeader(event: H3Event) {
return normalizeBridgeToken(getHeader(event, 'x-bridge-token'))
}
/**
* The identity behind a bridge token, from the app's own mirror.
*
* Bridge endpoints are called by the desktop app with only a token, so there is
* no session to resolve and no chance to refresh the mirror first. A token
* paired before the mirror existed would otherwise report "not connected" and
* push the user through pairing again, so a missing mirror row is backfilled
* from the website's User here rather than treated as "unknown user".
*
* PHASE 1 (app repo): drop the backfill — by then every token predates nothing
* and there is no User collection to read.
*/
/** Resolve the identity behind a bridge token from the app's own user store. */
export async function resolveBridgeUser(
user: unknown,
): Promise<AppUserDocument | null> {
@@ -46,17 +34,5 @@ export async function resolveBridgeUser(
const userId = String((user as { _id?: unknown })?._id ?? user)
if (!mongoose.isValidObjectId(userId)) return null
const mirrored = await AppUser.findById(userId)
if (mirrored) return mirrored
const { User } = await import('../models/User')
const websiteUser = await User.findById(userId)
if (!websiteUser) return null
return await mirrorAppUser({
subject: String(websiteUser._id),
email: websiteUser.email,
name: websiteUser.name,
role: websiteUser.role,
}, { force: true })
return await AppUser.findById(userId)
}