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 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<boolean> => {
// 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<boolean> => {
// 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 (

View File

@ -81,15 +81,22 @@ export class BusTicketsApiClient {
}
// Auth endpoints
async login(email: string, password: string): Promise<AuthTokens> {
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<User> {
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<void> {
await this.request('/api/v1/auth/otp/request', {
method: 'POST',
body: JSON.stringify({ email, phone }),
});
}
async logout(): Promise<void> {
await this.request('/api/v1/auth/logout', { method: 'POST' });
this.clearTokens();