Skip to content

Conversation

@najuna-brian
Copy link
Contributor

@najuna-brian najuna-brian commented Jan 23, 2026

PR Description

Overview

Adds a new getCurrentUser() method to the Formulus API that retrieves the authenticated username from the device's secure Keychain storage. This enables WebView apps (like AnthroCollect) to access the logged-in user information without requiring manual re-selection.
Closes https://github.com/Omo-Valley-Research-Project/AnthroCollect/issues/32


Changes

File Change Description
FormulusInterfaceDefinition.ts ✅ Add getCurrentUser() API interface definition
FormulusMessageHandlers.types.ts ✅ Add onGetCurrentUser Message handler type
FormulusMessageHandlers.ts ✅ Implement handler Fetch username from Keychain
generateInjectionScript.ts 🐛 Fix TypeScript syntax bug Remove invalid interface in .js output
FormulusInjectionScript.js ✅ Regenerated Includes new method
formulus-api.js ✅ Regenerated JSDoc updated

Implementation

API Method Signature:

getCurrentUser(): Promise<{username: string, displayName?: string}>
Return Value Example:

{
  username: "Eshetu",
  displayName: "Eshetu"
}

How It Works:

  1. WebView (AnthroCollect) calls window.formulus.getCurrentUser()
  2. Formulus Bridge invokes onGetCurrentUser handler
  3. React Native Keychain returns stored credentials
  4. WebView receives {username: "Eshetu", displayName: "Eshetu"}

Bug Fix Included

Issue: Injection script generator was outputting invalid TypeScript syntax in JavaScript files

This was causing linter errors like "Expression expected" and "Declaration or statement expected"

Fixed by removing TypeScript interface declarations from the JavaScript output template


Dependencies

Required by the corresponding AnthroCollect PR that removes the redundant user selection screen


Testing Checklist

  • Build and install Formulus Android app with these changes
  • Login with fieldworker credentials (e.g., "Eshetu")
  • Load AnthroCollect WebView
  • Verify getCurrentUser() returns correct username
  • Verify injection script has no syntax errors
  • Test on both Android and iOS (if applicable)

Technical Notes

• Username is stored in Keychain during login (Keychain.setGenericPassword)
• Method uses Keychain.getGenericPassword() to retrieve credentials securely
• Returns displayName field for future extensibility (e.g., mapping to full names)
• No breaking changes to existing API methods
• Injection scripts are auto-generated - run npm run generate after modifying the interface

Screenshot showing username an village

Screenshot_20260123-032814

@najuna-brian najuna-brian changed the title Add getCurrentUser API Method to Formulus [Formulus]Add getCurrentUser API Method to Formulus Jan 23, 2026
@najuna-brian najuna-brian changed the title [Formulus]Add getCurrentUser API Method to Formulus [Formulus] Add getCurrentUser API Method to Formulus Jan 23, 2026
@najuna-brian najuna-brian changed the title [Formulus] Add getCurrentUser API Method to Formulus feat: Add getCurrentUser API Method to Formulus Jan 23, 2026
@najuna-brian
Copy link
Contributor Author

This is required for https://github.com/Omo-Valley-Research-Project/AnthroCollect/pull/36 to be merged

Copy link
Contributor

@Mishael-2584 Mishael-2584 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the current user addition to app. And overall a smarter way to avoid selection and remove the user selection screen.

@najuna-brian najuna-brian merged commit 7953978 into OpenDataEnsemble:dev Jan 23, 2026
11 checks passed
@najuna-brian najuna-brian deleted the remove-selectuser-screen branch January 23, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants