feat(apps): bootstrap, env, i18n, providers, error pages and session proxy
- env validated with the env lib (NEXT_PUBLIC_API_ORIGIN, API_INTERNAL_ORIGIN,
site URL, support config); .env.example per app
- client bootstrap: API base under /v1, one shared session refresh, error
mapping; server bootstrap: cookie forwarding for server renders
- i18n instance for the server, bound to react-i18next on the client
- root layout, AppProviders, global-error, not-found and a page boundary in
every route group; instrumentation reports uncaught server errors
- proxy.ts refreshes an expired session before rendering
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 17:33:07 +00:00
|
|
|
import { configureErrorHandler } from '@lumina/libs/error-handler';
|
|
|
|
|
import { eventEmitter } from '@lumina/libs/event-emitter';
|
|
|
|
|
import { http } from '@lumina/libs/http';
|
|
|
|
|
import { mapApiErrorBody } from '@lumina/market/app/http';
|
|
|
|
|
import { setEnv as setMarketEnv } from '@lumina/market/env';
|
refactor(market,apps): drop the session proxy and restore auth in the browser
The server render no longer depends on auth: it reads no session and
forwards only FORWARDED_COOKIES (none today), so every visitor of a URL
gets the same HTML and the Next.js proxy is no longer needed.
- Remove proxy.ts from bull and bear, the app/session module, the
server auth and role guards, and the server caches that read the
viewer's own data. Public caches stay: channel, post, prediction stats.
- Add an auth store (status unknown | guest | member) filled by the
restoreSession action, which reads GET /auth/session once per load
from the AppShell's useSession hook.
- Login and register actions set the store, logout clears it; the
AppShell clears the query cache on auth.logout. No router.refresh.
- Add client AuthGuard (fallback, optional role) and GuestGuard, with
safeReturnPath limiting post-login redirects to same-site paths.
- readOnServer no longer redirects on 401.
- The browser HTTP client refreshes against AUTH_ENDPOINTS.refresh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 18:28:05 +00:00
|
|
|
import { AUTH_ENDPOINTS, AUTH_EVENTS } from '@lumina/market/features/auth';
|
feat(apps): bootstrap, env, i18n, providers, error pages and session proxy
- env validated with the env lib (NEXT_PUBLIC_API_ORIGIN, API_INTERNAL_ORIGIN,
site URL, support config); .env.example per app
- client bootstrap: API base under /v1, one shared session refresh, error
mapping; server bootstrap: cookie forwarding for server renders
- i18n instance for the server, bound to react-i18next on the client
- root layout, AppProviders, global-error, not-found and a page boundary in
every route group; instrumentation reports uncaught server errors
- proxy.ts refreshes an expired session before rendering
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 17:33:07 +00:00
|
|
|
|
|
|
|
|
import { API_VERSION_PATH } from '../constants';
|
|
|
|
|
import { clientEnv } from '../env';
|
|
|
|
|
import { ERROR_HANDLER_CONFIG } from './error-reporting';
|
|
|
|
|
|
|
|
|
|
// Fills the client module graph with public values only, before client components render (during
|
|
|
|
|
// SSR and in the browser). Idempotent: safe to run again.
|
|
|
|
|
setMarketEnv({
|
|
|
|
|
apiOrigin: clientEnv.NEXT_PUBLIC_API_ORIGIN,
|
|
|
|
|
baleHandle: clientEnv.NEXT_PUBLIC_BALE_HANDLE,
|
|
|
|
|
telegramHandle: clientEnv.NEXT_PUBLIC_TELEGRAM_HANDLE,
|
|
|
|
|
supportHours: clientEnv.NEXT_PUBLIC_SUPPORT_HOURS,
|
|
|
|
|
});
|
|
|
|
|
// The session lives in HttpOnly cookies the browser sends itself. A 401 runs one refresh for the
|
|
|
|
|
// whole app; when that fails the session is over and the shell signs the user out.
|
|
|
|
|
http.configure({
|
|
|
|
|
baseUrl: `${clientEnv.NEXT_PUBLIC_API_ORIGIN}${API_VERSION_PATH}`,
|
|
|
|
|
refresh: {
|
refactor(market,apps): drop the session proxy and restore auth in the browser
The server render no longer depends on auth: it reads no session and
forwards only FORWARDED_COOKIES (none today), so every visitor of a URL
gets the same HTML and the Next.js proxy is no longer needed.
- Remove proxy.ts from bull and bear, the app/session module, the
server auth and role guards, and the server caches that read the
viewer's own data. Public caches stay: channel, post, prediction stats.
- Add an auth store (status unknown | guest | member) filled by the
restoreSession action, which reads GET /auth/session once per load
from the AppShell's useSession hook.
- Login and register actions set the store, logout clears it; the
AppShell clears the query cache on auth.logout. No router.refresh.
- Add client AuthGuard (fallback, optional role) and GuestGuard, with
safeReturnPath limiting post-login redirects to same-site paths.
- readOnServer no longer redirects on 401.
- The browser HTTP client refreshes against AUTH_ENDPOINTS.refresh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 18:28:05 +00:00
|
|
|
endpoint: AUTH_ENDPOINTS.refresh,
|
feat(apps): bootstrap, env, i18n, providers, error pages and session proxy
- env validated with the env lib (NEXT_PUBLIC_API_ORIGIN, API_INTERNAL_ORIGIN,
site URL, support config); .env.example per app
- client bootstrap: API base under /v1, one shared session refresh, error
mapping; server bootstrap: cookie forwarding for server renders
- i18n instance for the server, bound to react-i18next on the client
- root layout, AppProviders, global-error, not-found and a page boundary in
every route group; instrumentation reports uncaught server errors
- proxy.ts refreshes an expired session before rendering
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 17:33:07 +00:00
|
|
|
onFailure: () =>
|
|
|
|
|
eventEmitter.emit(AUTH_EVENTS.logout, { reason: 'session-ended' }),
|
|
|
|
|
},
|
|
|
|
|
mapErrorBody: mapApiErrorBody,
|
|
|
|
|
});
|
|
|
|
|
configureErrorHandler(ERROR_HANDLER_CONFIG);
|