Files
billing/app/page.tsx
zooqueenandHanzo Dev 7f5f05758c Fix build: inline billing components, commerce client, and IAM auth
Published npm packages have issues:
- @hanzo/commerce v7.3.10 doesn't include the billing API client (only in unreleased v7.4.0)
- @hanzo/ui v5.3.34 exports billing from src/ but doesn't ship src/ in the tarball
- @hanzo/auth v2.7.1 source files reference @hanzo/ui/primitives which lacks type declarations

Solution: inline all three as self-contained modules:
- lib/commerce-client.ts — Commerce API client (balance, deposits, subscriptions, plans)
- lib/billing/ — BillingWorkspace + 5 sub-components + types (from @hanzo/ui source)
- lib/iam-auth.ts — OIDC/PKCE auth flow with Casdoor (hanzo.id)

Build passes: typecheck + next build → 4 static pages generated.

Co-authored-by: Hanzo Dev <[email protected]>
2026-02-23 19:05:49 -08:00

48 lines
1.4 KiB
TypeScript

'use client'
import { useState, useEffect } from 'react'
import { getOrgByHost, type BillingOrgConfig } from '@/lib/config'
import { isLoggedIn, startLogin, getCurrentUser, type IamUser } from '@/lib/iam-auth'
import { makeAuthConf } from '@/lib/auth'
import { BillingShell } from '@/lib/components/billing-shell'
export default function BillingPage() {
const [org, setOrg] = useState<BillingOrgConfig | null>(null)
const [user, setUser] = useState<IamUser | null>(null)
const [checked, setChecked] = useState(false)
useEffect(() => {
const detectedOrg = getOrgByHost(window.location.host)
setOrg(detectedOrg)
if (isLoggedIn()) {
setUser(getCurrentUser())
setChecked(true)
} else {
setChecked(true)
startLogin(makeAuthConf(detectedOrg))
}
}, [])
if (!org || !checked) {
return (
<main className="flex min-h-screen items-center justify-center bg-bg">
<div className="h-6 w-6 animate-spin rounded-full border-2 border-text-dim border-t-brand" />
</main>
)
}
if (!user) {
return (
<main className="flex min-h-screen items-center justify-center bg-bg">
<div className="text-center">
<div className="mx-auto h-6 w-6 animate-spin rounded-full border-2 border-text-dim border-t-brand" />
<p className="mt-4 text-sm text-text-muted">Redirecting to sign in...</p>
</div>
</main>
)
}
return <BillingShell org={org} user={user} />
}