mirror of
https://github.com/Afilmory/afilmory
synced 2026-02-01 22:48:17 +00:00
@@ -31,8 +31,6 @@ const logger = createLogger('Auth')
|
||||
|
||||
@injectable()
|
||||
export class AuthProvider implements OnModuleInit {
|
||||
private instances = new Map<string, Promise<BetterAuthInstance>>()
|
||||
|
||||
constructor(
|
||||
private readonly config: AuthConfig,
|
||||
private readonly drizzleProvider: DrizzleProvider,
|
||||
@@ -66,21 +64,6 @@ export class AuthProvider implements OnModuleInit {
|
||||
}
|
||||
}
|
||||
|
||||
private buildCookiePrefix(tenantSlug: string | null): string {
|
||||
if (!tenantSlug) {
|
||||
return 'better-auth'
|
||||
}
|
||||
|
||||
const sanitizedSlug = tenantSlug
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replaceAll(/[^a-z0-9_-]/g, '-')
|
||||
.replaceAll(/-+/g, '-')
|
||||
.replaceAll(/^-|-$/g, '')
|
||||
|
||||
return sanitizedSlug ? `better-auth-${sanitizedSlug}` : 'better-auth'
|
||||
}
|
||||
|
||||
private async resolveTenantIdOrProvision(tenantSlug: string | null): Promise<string | null> {
|
||||
const tenantIdFromContext = this.resolveTenantIdFromContext()
|
||||
if (tenantIdFromContext) {
|
||||
@@ -119,37 +102,7 @@ export class AuthProvider implements OnModuleInit {
|
||||
}
|
||||
}
|
||||
|
||||
private determineProtocol(host: string, provided: string | null): string {
|
||||
if (provided && (provided === 'http' || provided === 'https')) {
|
||||
return provided
|
||||
}
|
||||
if (host.includes('localhost') || host.startsWith('127.') || host.startsWith('0.0.0.0')) {
|
||||
return 'http'
|
||||
}
|
||||
return 'https'
|
||||
}
|
||||
|
||||
private applyTenantSlugToHost(host: string, fallbackHost: string, tenantSlug: string | null): string {
|
||||
if (!tenantSlug) {
|
||||
return host
|
||||
}
|
||||
|
||||
const [hostName, hostPort] = host.split(':') as [string, string?]
|
||||
if (hostName.startsWith(`${tenantSlug}.`)) {
|
||||
return host
|
||||
}
|
||||
|
||||
const [fallbackName, fallbackPort] = fallbackHost.split(':') as [string, string?]
|
||||
if (hostName !== fallbackName) {
|
||||
return host
|
||||
}
|
||||
|
||||
const portSegment = hostPort ?? fallbackPort
|
||||
return portSegment ? `${tenantSlug}.${fallbackName}:${portSegment}` : `${tenantSlug}.${fallbackName}`
|
||||
}
|
||||
|
||||
private buildBetterAuthProvidersForHost(
|
||||
tenantSlug: string | null,
|
||||
providers: SocialProvidersConfig,
|
||||
oauthGatewayUrl: string | null,
|
||||
): Record<string, { clientId: string; clientSecret: string; redirectUri?: string }> {
|
||||
@@ -207,11 +160,7 @@ export class AuthProvider implements OnModuleInit {
|
||||
options: AuthModuleOptions,
|
||||
): Promise<BetterAuthInstance> {
|
||||
const db = this.drizzleProvider.getDb()
|
||||
const socialProviders = this.buildBetterAuthProvidersForHost(
|
||||
tenantSlug,
|
||||
options.socialProviders,
|
||||
options.oauthGatewayUrl,
|
||||
)
|
||||
const socialProviders = this.buildBetterAuthProvidersForHost(options.socialProviders, options.oauthGatewayUrl)
|
||||
|
||||
// Use tenant-aware adapter for multi-tenant user/account isolation
|
||||
// This ensures that user lookups (by email) and account lookups (by provider)
|
||||
|
||||
Reference in New Issue
Block a user