mirror of
https://github.com/hanzoai/billing.git
synced 2026-10-30 18:46:54 +00:00
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]>
48 lines
1.4 KiB
TypeScript
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} />
|
|
}
|