import { Repository } from 'typeorm'; import { ISocialAccount } from '../interfaces/entities.interface'; import { BaseUser, BaseSocialAccount } from '../entities'; import { AuthService } from './auth.service'; import { InternalAuthAuditService as AuthAuditService } from './auth-audit.service'; import { NAuthLogger } from '../utils/nauth-logger'; import { SocialProviderRegistry } from './social-provider-registry.service'; import { LinkSocialAccountDTO, LinkSocialAccountResponseDTO, GetLinkedAccountsDTO, GetLinkedAccountsResponseDTO, UnlinkSocialAccountDTO, UnlinkSocialAccountResponseDTO, CanSetPasswordDTO, CanSetPasswordResponseDTO, SetPasswordForSocialUserDTO, SetPasswordForSocialUserResponseDTO } from '../dto/social-auth.dto'; /** * Social Auth Service * * Service for managing social authentication accounts and their relationships. * This service provides: * - Social account linking/unlinking * - Account management for social users * - Password management for social-only users * - Querying linked accounts * * **Note:** For OAuth authentication flows (login/signup), use `SocialRedirectHandler` * or the frontend SDK's `loginWithSocial()` method. * * **Optional Feature:** Only available when social auth provider modules are imported. * * **Usage:** * ```typescript * // NestJS * imports: [ * AuthModule.forRoot(config), * GoogleSocialAuthModule, // Enables Google OAuth * AppleSocialAuthModule, // Enables Apple Sign In * ] * * // Then inject and use * constructor(private socialAuthService: SocialAuthService) {} * * const result = await this.socialAuthService.linkSocialAccount({ userId, provider, code, state }); * const accounts = await this.socialAuthService.getLinkedAccounts({ userId }); * ``` */ export declare class SocialAuthService { private readonly providerRegistry; private readonly userRepository; private readonly socialAccountRepository; private readonly authService; private readonly logger; private readonly auditService?; /** * Get current user from authenticated context * * @returns Current authenticated user * @throws {NAuthException} If user not found in context */ private getCurrentUserOrThrow; constructor(providerRegistry: SocialProviderRegistry, userRepository: Repository, socialAccountRepository: Repository, authService: AuthService | null, // Can be null to break circular dependency logger: NAuthLogger, auditService?: AuthAuditService | undefined); /** * Link social account to existing authenticated user * * Connects a social provider to an already logged-in user's account. * User must be authenticated before calling this method. * * @param dto - Request DTO containing userId, provider, code, and state * @returns Response DTO with success message and provider name * @throws {NAuthException} SOCIAL_ALREADY_LINKED, NOT_FOUND, etc. * * @example * ```typescript * const dto = { * userId: user.sub, * provider: 'apple', * code: req.query.code, * state: req.query.state * }; * const result = await socialAuthService.linkSocialAccount(dto); * ``` */ linkSocialAccount(dto: LinkSocialAccountDTO): Promise; /** * List available social auth providers * * Returns names of all registered and enabled social auth providers. * Useful for displaying available login options in the UI. * * @returns Array of provider names (e.g., ['google', 'apple', 'facebook']) * * @example * ```typescript * const providers = socialAuthService.listAvailableProviders(); * // Display social login buttons based on available providers * ``` */ listAvailableProviders(): string[]; /** * Get linked social accounts for a user * * @param dto - Request DTO containing userId * @returns Response DTO with array of linked social accounts * @throws {NAuthException} NOT_FOUND when user is not found * * @example * ```typescript * const dto = { userId: 'user-uuid' }; * const accounts = await socialAuthService.getLinkedAccounts(dto); * console.log(accounts.accounts); // [{ provider: 'google', ... }] * ``` */ getLinkedAccounts(dto: GetLinkedAccountsDTO): Promise; /** * Unlink social account from user * * @param dto - Request DTO containing userId and provider * @returns Response DTO with success message * @throws {NAuthException} NOT_FOUND when user or account is not found * * @example * ```typescript * const dto = { userId: 'user-uuid', provider: 'google' }; * await socialAuthService.unlinkSocialAccount(dto); * ``` */ unlinkSocialAccount(dto: UnlinkSocialAccountDTO): Promise; /** * Check if user can set a password * Users with social-only accounts can set passwords * * @param dto - Request DTO containing userId * @returns Response DTO indicating whether user can set password * * @example * ```typescript * const dto = { userId: 'user-uuid' }; * const result = await socialAuthService.canSetPassword(dto); * if (result.canSetPassword) { * // Allow user to set password * } * ``` */ canSetPassword(dto: CanSetPasswordDTO): Promise; /** * Set password for social-only user * * @param dto - Request DTO containing userId and password * @returns Response DTO with success message * @throws {NAuthException} NOT_FOUND when user is not found * @throws {NAuthException} VALIDATION_FAILED when user already has a password * * @example * ```typescript * const dto = { userId: 'user-uuid', password: 'newpassword' }; * await socialAuthService.setPasswordForSocialUser(dto); * ``` */ setPasswordForSocialUser(dto: SetPasswordForSocialUserDTO): Promise; /** * Find social account by provider and provider ID * * @param provider - Provider name (e.g., 'google', 'apple') * @param providerId - Provider user ID * @returns Social account with user relation, or null * @internal - For use by BaseSocialAuthProviderService */ findSocialAccountByProvider(provider: string, providerId: string): Promise; /** * Find social account by user ID and provider * * @param userId - User ID (internal) * @param provider - Provider name * @returns Social account or null * @internal - For use by BaseSocialAuthProviderService */ findSocialAccountByUser(userId: number, provider: string): Promise; /** * Create or update social account * * @param userId - User ID (internal) * @param provider - Provider name * @param providerId - Provider user ID * @param providerEmail - Provider email * @param metadata - Optional raw profile data * @internal - For use by BaseSocialAuthProviderService */ createOrUpdateSocialAccount(userId: number, provider: string, providerId: string, providerEmail?: string | null, metadata?: Record): Promise; /** * Update user's social authentication flags * * @param userId - User ID (internal) * @internal - For use by BaseSocialAuthProviderService */ updateUserSocialFlags(userId: number): Promise; } //# sourceMappingURL=social-auth.service.d.ts.map