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 <noreply@anthropic.com>
This commit is contained in:
user 2026-02-04 09:21:47 +00:00
parent b2b19aac4e
commit 299a91c83e
2 changed files with 31 additions and 28 deletions

View File

@ -9,11 +9,8 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
import { useApi } from './ApiContext'; import { useApi } from './ApiContext';
import type { User, AuthTokens } from '@/types'; import type { User, AuthTokens } from '@/types';
// Dynamic import for native-only modules // Biometric authentication is disabled in this build
let LocalAuthentication: typeof import('expo-local-authentication') | null = null; // expo-local-authentication requires native module compilation
if (Platform.OS !== 'web') {
LocalAuthentication = require('expo-local-authentication');
}
interface StoredAuth { interface StoredAuth {
accessToken: string; accessToken: string;
@ -271,26 +268,17 @@ export function AuthProvider({ children }: { children: ReactNode }) {
}, [user, api]); }, [user, api]);
const checkBiometric = async (): Promise<boolean> => { const checkBiometric = async (): Promise<boolean> => {
// Biometric not available on web // Biometric authentication is disabled in this build
if (Platform.OS === 'web' || !LocalAuthentication) { // To enable: install expo-local-authentication and update this function
return false; console.log('Biometric authentication disabled in this build');
} return false;
const hasHardware = await LocalAuthentication.hasHardwareAsync();
const isEnrolled = await LocalAuthentication.isEnrolledAsync();
return hasHardware && isEnrolled;
}; };
const authenticateWithBiometric = async (): Promise<boolean> => { const authenticateWithBiometric = async (): Promise<boolean> => {
// Biometric not available on web // Biometric authentication is disabled in this build
if (Platform.OS === 'web' || !LocalAuthentication) { // To enable: install expo-local-authentication and update this function
return false; console.log('Biometric authentication disabled in this build');
} return false;
const result = await LocalAuthentication.authenticateAsync({
promptMessage: 'Authenticate to access BUS-Tickets',
cancelLabel: 'Cancel',
disableDeviceFallback: false,
});
return result.success;
}; };
return ( return (

View File

@ -81,15 +81,22 @@ export class BusTicketsApiClient {
} }
// Auth endpoints // Auth endpoints
async login(email: string, password: string): Promise<AuthTokens> { async login(params: {
const response = await this.request<{ data: AuthTokens }>( 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', '/api/v1/auth/login',
{ {
method: 'POST', method: 'POST',
body: JSON.stringify({ email, password }), body: JSON.stringify(params),
} }
); );
this.tokens = response.data; this.tokens = response.data.tokens;
return response.data; return response.data;
} }
@ -98,17 +105,25 @@ export class BusTicketsApiClient {
password: string; password: string;
name: string; name: string;
phone?: string; phone?: string;
}): Promise<User> { }): Promise<{ user: User; tokens: AuthTokens }> {
const response = await this.request<{ data: User }>( const response = await this.request<{ data: { user: User; tokens: AuthTokens } }>(
'/api/v1/auth/register', '/api/v1/auth/register',
{ {
method: 'POST', method: 'POST',
body: JSON.stringify(data), body: JSON.stringify(data),
} }
); );
this.tokens = response.data.tokens;
return response.data; return response.data;
} }
async requestOtp(email?: string, phone?: string): Promise<void> {
await this.request('/api/v1/auth/otp/request', {
method: 'POST',
body: JSON.stringify({ email, phone }),
});
}
async logout(): Promise<void> { async logout(): Promise<void> {
await this.request('/api/v1/auth/logout', { method: 'POST' }); await this.request('/api/v1/auth/logout', { method: 'POST' });
this.clearTokens(); this.clearTokens();