Skip to content

Commit 49d3386

Browse files
authored
Merge pull request #381 from wavect/wsdt/registration-safety
chore: emulator backend support, auth service slightly more resilient
2 parents 670f7cd + c801108 commit 49d3386

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

backend/custom-templates/runtime.mustache

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
/* eslint-disable */
33
{{>licenseInfo}}
44

5-
import Constants from 'expo-constants';
6-
import { IS_DEVELOPMENT_BUILD } from "../../../utils/env.utils";
7-
8-
export const BASE_PATH = ((IS_DEVELOPMENT_BUILD ?
9-
`http://${Constants.expoConfig?.hostUri?.split(':').shift()?.concat(':3000')}`
10-
: "https://api.offlinery.io")+ "/v1").replace(
11-
/\/+$/,
12-
"",
13-
);
5+
import Constants from "expo-constants";
6+
import { IS_DEVELOPMENT_BUILD, USE_EMULATOR } from "../../../utils/env.utils";
7+
8+
const DEV_BASE_URI = USE_EMULATOR ? "10.0.2.2" : Constants.expoConfig?.hostUri?.split(":").shift()
9+
export const BASE_PATH = (
10+
(IS_DEVELOPMENT_BUILD
11+
? `http://${DEV_BASE_URI?.concat(":3000")}`
12+
: "https://api.offlinery.io") + "/v1"
13+
).replace(/\/+$/, "");
1414

1515
export interface ConfigurationParameters {
1616
basePath?: string; // override base path

mobile/api/gen/src/runtime.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
*/
1414

1515
import Constants from "expo-constants";
16-
import { IS_DEVELOPMENT_BUILD } from "../../../utils/env.utils";
16+
import { IS_DEVELOPMENT_BUILD, USE_EMULATOR } from "../../../utils/env.utils";
1717

18+
const DEV_BASE_URI = USE_EMULATOR
19+
? "10.0.2.2"
20+
: Constants.expoConfig?.hostUri?.split(":").shift();
1821
export const BASE_PATH = (
1922
(IS_DEVELOPMENT_BUILD
20-
? `http://${Constants.expoConfig?.hostUri?.split(":").shift()?.concat(":3000")}`
23+
? `http://${DEV_BASE_URI?.concat(":3000")}`
2124
: "https://api.offlinery.io") + "/v1"
2225
).replace(/\/+$/, "");
2326

mobile/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"start:prod": "expo start --no-dev --minify",
1313
"start:tunnel": "expo start --tunnel",
1414
"android": "npx concurrently \"EXPO_PUBLIC_ENVIRONMENT=development expo run:android\" \"npx react-native log-android\"",
15+
"android:emulator": "EXPO_PUBLIC_USE_EMULATOR=true pnpm android",
1516
"ios": "EXPO_PUBLIC_ENVIRONMENT=development expo run:ios",
1617
"ios:device": "EXPO_PUBLIC_ENVIRONMENT=development expo run:ios --device",
1718
"ios:dev": "EXPO_PUBLIC_ENVIRONMENT=development expo run:ios",

mobile/services/auth.service.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,22 @@ export const registerUser = async (
9999
const { user, accessToken, refreshToken } = signInResponseDTO;
100100
console.log("User created successfully:", user);
101101

102-
await deleteOnboardingState();
103-
104-
// Update the user state
105-
await refreshUserData(dispatch, user, accessToken, refreshToken);
106-
107102
// Navigate to the next screen or update the UI as needed
108103
onSuccess();
104+
105+
try {
106+
await deleteOnboardingState();
107+
108+
// Update the user state
109+
await refreshUserData(dispatch, user, accessToken, refreshToken);
110+
} catch (err) {
111+
console.error("User registration postWork only failed: ", err);
112+
Sentry.captureException(err, {
113+
tags: {
114+
userContext: "registration:postWork",
115+
},
116+
});
117+
}
109118
} catch (error: any) {
110119
console.error("Error creating user:", error, JSON.stringify(error));
111120
onError(error);

mobile/utils/env.utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
export const IS_DEVELOPMENT_BUILD =
22
process.env.EXPO_PUBLIC_ENVIRONMENT?.trim() === "development";
3+
4+
export const USE_EMULATOR =
5+
process.env.EXPO_PUBLIC_USE_EMULATOR?.trim() === "true";

0 commit comments

Comments
 (0)