From 299a91c83e70c2310f4c68f1b8c963b2fe976440 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 4 Feb 2026 09:21:47 +0000 Subject: [PATCH] Fix expo-local-authentication import, update ApiClient - Remove expo-local-authentication dynamic import (causes build failure) - Add stub biometric functions (disabled in this build) - Update ApiClient login/register to match AuthContext usage - Add requestOtp method to ApiClient Co-Authored-By: Claude Opus 4.5 --- src/contexts/AuthContext.tsx | 32 ++++++++++---------------------- src/services/ApiClient.ts | 27 +++++++++++++++++++++------ 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index a5b64ee..930e751 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -9,11 +9,8 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; import { useApi } from './ApiContext'; import type { User, AuthTokens } from '@/types'; -// Dynamic import for native-only modules -let LocalAuthentication: typeof import('expo-local-authentication') | null = null; -if (Platform.OS !== 'web') { - LocalAuthentication = require('expo-local-authentication'); -} +// Biometric authentication is disabled in this build +// expo-local-authentication requires native module compilation interface StoredAuth { accessToken: string; @@ -271,26 +268,17 @@ export function AuthProvider({ children }: { children: ReactNode }) { }, [user, api]); const checkBiometric = async (): Promise => { - // Biometric not available on web - if (Platform.OS === 'web' || !LocalAuthentication) { - return false; - } - const hasHardware = await LocalAuthentication.hasHardwareAsync(); - const isEnrolled = await LocalAuthentication.isEnrolledAsync(); - return hasHardware && isEnrolled; + // Biometric authentication is disabled in this build + // To enable: install expo-local-authentication and update this function + console.log('Biometric authentication disabled in this build'); + return false; }; const authenticateWithBiometric = async (): Promise => { - // Biometric not available on web - if (Platform.OS === 'web' || !LocalAuthentication) { - return false; - } - const result = await LocalAuthentication.authenticateAsync({ - promptMessage: 'Authenticate to access BUS-Tickets', - cancelLabel: 'Cancel', - disableDeviceFallback: false, - }); - return result.success; + // Biometric authentication is disabled in this build + // To enable: install expo-local-authentication and update this function + console.log('Biometric authentication disabled in this build'); + return false; }; return ( diff --git a/src/services/ApiClient.ts b/src/services/ApiClient.ts index 4f057db..f4f3ad0 100644 --- a/src/services/ApiClient.ts +++ b/src/services/ApiClient.ts @@ -81,15 +81,22 @@ export class BusTicketsApiClient { } // Auth endpoints - async login(email: string, password: string): Promise { - const response = await this.request<{ data: AuthTokens }>( + async login(params: { + provider: 'email' | 'google' | 'facebook' | 'apple' | 'phone'; + email?: string; + password?: string; + idToken?: string; + phone?: string; + otp?: string; + }): Promise<{ user: User; tokens: AuthTokens }> { + const response = await this.request<{ data: { user: User; tokens: AuthTokens } }>( '/api/v1/auth/login', { method: 'POST', - body: JSON.stringify({ email, password }), + body: JSON.stringify(params), } ); - this.tokens = response.data; + this.tokens = response.data.tokens; return response.data; } @@ -98,17 +105,25 @@ export class BusTicketsApiClient { password: string; name: string; phone?: string; - }): Promise { - const response = await this.request<{ data: User }>( + }): Promise<{ user: User; tokens: AuthTokens }> { + const response = await this.request<{ data: { user: User; tokens: AuthTokens } }>( '/api/v1/auth/register', { method: 'POST', body: JSON.stringify(data), } ); + this.tokens = response.data.tokens; return response.data; } + async requestOtp(email?: string, phone?: string): Promise { + await this.request('/api/v1/auth/otp/request', { + method: 'POST', + body: JSON.stringify({ email, phone }), + }); + } + async logout(): Promise { await this.request('/api/v1/auth/logout', { method: 'POST' }); this.clearTokens();