refactor: simplify authentication instance creation in AuthProvider

- Removed unnecessary cookie prefix handling and streamlined the instance creation process in the AuthProvider class.
- Updated the SuperAdminTenantManager component by removing unused button properties and cleaning up the status badge rendering logic.

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2025-12-04 16:17:58 +08:00
parent e8550cee42
commit ed4fcada7d
2 changed files with 3 additions and 28 deletions

View File

@@ -212,7 +212,6 @@ export class AuthProvider implements OnModuleInit {
options.socialProviders,
options.oauthGatewayUrl,
)
const cookiePrefix = this.buildCookiePrefix(tenantSlug)
// Use tenant-aware adapter for multi-tenant user/account isolation
// This ensures that user lookups (by email) and account lookups (by provider)
@@ -312,7 +311,6 @@ export class AuthProvider implements OnModuleInit {
},
},
advanced: {
cookiePrefix,
database: {
generateId: () => generateId(),
},
@@ -379,21 +377,8 @@ export class AuthProvider implements OnModuleInit {
const requestedHost = (endpoint.host ?? fallbackHost).trim().toLowerCase()
const tenantSlugFromContext = this.resolveTenantSlugFromContext()
const tenantSlug = tenantSlugFromContext ?? extractTenantSlugFromHost(requestedHost, options.baseDomain)
const host = this.applyTenantSlugToHost(requestedHost || fallbackHost, fallbackHost, tenantSlug)
const protocol = this.determineProtocol(host, endpoint.protocol)
const optionSignature = this.computeOptionsSignature(options)
const cacheKey = `${protocol}://${host}::${tenantSlug}::${optionSignature}`
if (!this.instances.has(cacheKey)) {
const instancePromise = this.createAuthForEndpoint(tenantSlug, options).then((instance) => {
logger.info(`Better Auth initialized for ${cacheKey}`)
return instance
})
this.instances.set(cacheKey, instancePromise)
}
return await this.instances.get(cacheKey)!
const instancePromise = this.createAuthForEndpoint(tenantSlug, options)
return await instancePromise
}
private computeOptionsSignature(options: AuthModuleOptions): string {

View File

@@ -256,8 +256,6 @@ export function SuperAdminTenantManager() {
</div>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="icon"
className="size-8"
disabled={page <= 1 || tenantsQuery.isFetching}
onClick={() => setPage((p) => p - 1)}
@@ -268,8 +266,6 @@ export function SuperAdminTenantManager() {
{page} / {totalPages || 1}
</div>
<Button
variant="outline"
size="icon"
className="size-8"
disabled={page >= totalPages || tenantsQuery.isFetching}
onClick={() => setPage((p) => p + 1)}
@@ -346,13 +342,7 @@ function StatusBadge({ status, banned }: { status: SuperAdminTenantSummary['stat
</span>
)
}
if (status === 'pending') {
return (
<span className="bg-blue-500/10 text-blue-400 rounded-full px-2 py-0.5 text-xs">
{t('superadmin.tenants.status.pending')}
</span>
)
}
return (
<span className="bg-slate-500/10 text-slate-400 rounded-full px-2 py-0.5 text-xs">
{t('superadmin.tenants.status.inactive')}