Files
zeekayandHanzo Dev 0e1f4b70a5 refactor(dashboard): take the sign-in flow from @luxfi/ui/auth
Three files here restated the same OIDC wiring that lux/market restated too, and
that lux/explore restated a fourth, PKCE-less way. `@luxfi/ui/[email protected]` is
that flow, once — `AuthProvider` (identity read + PKCE login, bound to the host)
and `AuthCallback` (state check, verifier, code→token).

What is left here is the only part that is MPC's: the middleware session flag,
and the MPC API's own JWT minted from the IAM token. That exchange stays
DOWNSTREAM — the user is signed in whether or not the MPC API answers.

Behaviour is unchanged: same `/auth/callback` path, same `lux-mpc` client
resolved from the host, same landing on /dashboard. `tsc --noEmit` reports only
the pre-existing `globals.css` side-effect-import error.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-27 18:26:29 -07:00

46 lines
1.8 KiB
TypeScript

'use client'
import { AppProvider } from '@luxfi/ui'
import { AuthProvider } from '@luxfi/ui/auth'
import { useEffect, useState, type ReactNode } from 'react'
import { clearTokens } from '@/lib/auth'
// The root providers: brand + identity, both resolved from the HOST.
//
// `AppProvider` (@luxfi/ui) carries the white-label — brand, gui theme row,
// OIDC issuer and IAM client id all come from the Host header, so one image
// serves mpc.lux.network, mpc.zoo.network and mpc.pars.network with no
// per-deployment branding table. It also owns the QueryClient, so there is one
// query cache per surface instead of one per provider file.
//
// `AuthProvider` (@luxfi/ui/auth) is the identity read AND the PKCE login,
// bound to that same host. This file used to hand-roll the credential half —
// `configureIam` + `startLogin` + `logout` — and so did lux/market, while
// lux/explore hand-built an authorize URL with no PKCE at all. One flow now
// lives in the design system; a surface names only where a session lands and
// what of its OWN it drops on the way out.
//
// NEXT_PUBLIC_HOST is the LOCAL-DEV seam and nothing else: `localhost` has no
// brand to resolve, so a developer names the host the surface stands in for.
// It is unset in every deployment, where the real Host header answers.
const DEV_HOST = process.env.NEXT_PUBLIC_HOST
export function Providers({ children }: { children: ReactNode }) {
const [host, setHost] = useState<string | undefined>(undefined)
useEffect(() => {
const real = window.location.host
const local = /^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/.test(real)
setHost(local && DEV_HOST ? DEV_HOST : real)
}, [])
return (
<AppProvider host={host}>
<AuthProvider redirect="/dashboard" onSignOut={clearTokens}>
{children}
</AuthProvider>
</AppProvider>
)
}