UNPKG

@oxyhq/services

Version:

Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀

58 lines • 2.6 kB
import type React from 'react'; import { type ReactNode } from 'react'; import { OxyServices } from '../../core'; import type { User, ApiError } from '../../models/interfaces'; import type { ClientSession, MinimalUserData } from '../../models/session'; import type { BottomSheetController } from '../navigation/types'; import type { RouteName } from '../navigation/routes'; import type { LanguageMetadata } from '../../utils/languageUtils'; import type { UseFollowHook } from '../hooks/useFollow.types'; export interface OxyContextState { user: User | null; minimalUser: MinimalUserData | null; sessions: ClientSession[]; activeSessionId: string | null; isAuthenticated: boolean; isLoading: boolean; isTokenReady: boolean; error: string | null; currentLanguage: string; currentLanguageMetadata: LanguageMetadata | null; currentLanguageName: string; currentNativeLanguageName: string; login: (username: string, password: string, deviceName?: string) => Promise<User>; logout: (targetSessionId?: string) => Promise<void>; logoutAll: () => Promise<void>; signUp: (username: string, email: string, password: string) => Promise<User>; completeMfaLogin?: (mfaToken: string, code: string) => Promise<User>; switchSession: (sessionId: string) => Promise<void>; removeSession: (sessionId: string) => Promise<void>; refreshSessions: () => Promise<void>; setLanguage: (languageId: string) => Promise<void>; getDeviceSessions: () => Promise<any[]>; logoutAllDeviceSessions: () => Promise<void>; updateDeviceName: (deviceName: string) => Promise<void>; oxyServices: OxyServices; bottomSheetRef?: React.RefObject<BottomSheetController | null>; showBottomSheet?: (screenOrConfig?: RouteName | string | { screen: RouteName | string; props?: Record<string, any>; }) => void; hideBottomSheet?: () => void; useFollow?: UseFollowHook; } declare const OxyContext: React.Context<OxyContextState | null>; export interface OxyContextProviderProps { children: ReactNode; oxyServices?: OxyServices; baseURL?: string; storageKeyPrefix?: string; onAuthStateChange?: (user: User | null) => void; onError?: (error: ApiError) => void; bottomSheetRef?: React.RefObject<BottomSheetController | null>; } export declare const OxyProvider: React.FC<OxyContextProviderProps>; export declare const OxyContextProvider: React.FC<OxyContextProviderProps>; export declare const useOxy: () => OxyContextState; export default OxyContext; //# sourceMappingURL=OxyContext.d.ts.map