UNPKG

@pagamio/frontend-commons-lib

Version:

Pagamio library for Frontend reusable components like the form engine and table container

75 lines (74 loc) 2.53 kB
/** * @fileoverview Strapi authenticator processor implementation * Handles Strapi-specific authentication flows */ import type { AuthResponse, CustomAuthConfig } from '../../types'; import type { AuthenticatorProcessor } from '../types'; /** * Strapi user structure */ export interface StrapiUser { id: number; documentId: string; username: string; email: string; provider: string; confirmed: boolean; blocked: boolean; createdAt: string; updatedAt: string; publishedAt: string; firstName: string; lastName: string; company: string; isFirstTimeLogin: boolean; hasCompletedOnboarding: boolean; hasSkippedOnboarding: boolean; onBoardingReminderTime: string; loginCount: number; lastLoginAt: string; role: { id: number; documentId: string; name: string; description: string; type: string; createdAt: string; updatedAt: string; publishedAt: string; }; } /** * Strapi authentication response structure */ export interface StrapiAuthResponse { jwt: string; user: StrapiUser; } /** * Transforms a valid Strapi response into our application's auth response format * @param strapiResponse - Validated Strapi auth response * @returns Transformed auth response */ export declare function transformStrapiResponse<T extends CustomAuthConfig>(strapiResponse: StrapiAuthResponse): AuthResponse<T>; /** * Validates if the response is a valid Strapi authentication response * @param response - API response to validate * @returns Boolean indicating if response is a valid Strapi auth response */ export declare function isStrapiAuthResponse(response: unknown): response is StrapiAuthResponse; /** * Strapi authenticator processor * Handles authentication process specific to Strapi backend * @template T - Type extending CustomAuthConfig */ export declare class StrapiAuthenticatorProcessor<T extends CustomAuthConfig> implements AuthenticatorProcessor<T> { /** * Process login credentials using the Strapi authentication flow * @param credentials - User login credentials * @param rememberMe - Whether to remember the user session * @param login - The login function from auth context * @returns Promise resolving to authentication response */ processLogin(credentials: Record<string, unknown>, rememberMe: boolean, login: (credentials: T['Credentials'], rememberMe: boolean) => Promise<AuthResponse<T>>): Promise<AuthResponse<T>>; }