Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions formulus/src/api/synkronus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ class SynkronusApi {
private config: Configuration | null = null;

async getApi(): Promise<DefaultApi> {
// Always check current serverUrl from storage to handle changes
const rawSettings = await AsyncStorage.getItem('@settings');
if (!rawSettings) throw new Error('Missing app settings');

const {serverUrl} = JSON.parse(rawSettings);

// If config exists but serverUrl changed, clear cache
if (this.config && this.config.basePath !== serverUrl) {
this.api = null;
this.config = null;
}

// If API exists, return it (serverUrl hasn't changed)
if (this.api) return this.api;

// Load settings if not already loaded
// Load config if not already loaded
if (!this.config) {
const rawSettings = await AsyncStorage.getItem('@settings');
if (!rawSettings) throw new Error('Missing app settings');

const {serverUrl} = JSON.parse(rawSettings);
this.config = new Configuration({
basePath: serverUrl,
accessToken: async () => {
Expand Down
2 changes: 1 addition & 1 deletion formulus/src/navigation/MainAppNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const MainAppNavigator: React.FC = () => {
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{title: 'Settings'}}
options={{headerShown: false}}
/>
<Stack.Screen
name="FormManagement"
Expand Down
Loading
Loading