You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_Patient_App_New/contexts/AuthContext.tsx

32 lines
805 B
TypeScript

// ...existing imports...
import { apiService } from '../services/api';
// ...existing code...
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
// ...existing state...
const login = async (nationalId: string, password: string) => {
try {
setIsLoading(true);
// Call the real API
const user = await apiService.getUserDetails(nationalId, password);
// Store user data
await AsyncStorage.setItem('user', JSON.stringify(user));
await AsyncStorage.setItem('authToken', user.authToken);
setUser(user);
} catch (error) {
console.error('Login error:', error);
throw new Error('Invalid credentials or network error');
} finally {
setIsLoading(false);
}
};
// ...existing code...
};