From 18490bd8b0d85b625de896870f46ab594b116143 Mon Sep 17 00:00:00 2001 From: solderq35 Date: Mon, 1 Apr 2024 14:09:40 -0700 Subject: [PATCH 1/5] maybe fix test login --- app/segments/drill/[id]/submission/input.js | 6 +++--- context/Auth.js | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/segments/drill/[id]/submission/input.js b/app/segments/drill/[id]/submission/input.js index 204908c4..afee1c9e 100644 --- a/app/segments/drill/[id]/submission/input.js +++ b/app/segments/drill/[id]/submission/input.js @@ -418,7 +418,7 @@ export default function Input({ drillInfo, setToggleResult, setOutputData }) { { - descriptionModalRef.current ?.present(); + descriptionModalRef.current?.present(); }} color={"#F24E1E"} /> @@ -468,7 +468,7 @@ export default function Input({ drillInfo, setToggleResult, setOutputData }) { icon={getIconByKey(item.id)} prompt={item.prompt} distanceMeasure={item.distanceMeasure} - inputValue={inputValues[displayedShot] ?.[item.id] || ""} + inputValue={inputValues[displayedShot]?.[item.id] || ""} onInputChange={(newText) => { handleInputChange(item.id, newText); }} @@ -573,7 +573,7 @@ export default function Input({ drillInfo, setToggleResult, setOutputData }) { { - navModalRef.current ?.present(); + navModalRef.current?.present(); }} > View all shots diff --git a/context/Auth.js b/context/Auth.js index b6b8bac0..7860f36f 100644 --- a/context/Auth.js +++ b/context/Auth.js @@ -45,15 +45,20 @@ export const AuthProvider = ({ children }) => { useEffect(() => { //if this code is not in here, it'll run for infinite times onAuthStateChanged(auth, (currentUserId) => { + // keep this log outside if statement to confirm e.g. logout of test user console.log("user changed"); - if (currentUserId) { - setCurrentUserId(currentUserId.uid ?? "Error (uid)"); + + // prevent "persistent login" of regular user login from conflicting with test user + if (!process.env.EXPO_PUBLIC_TEST_UID) { + if (currentUserId) { + setCurrentUserId(currentUserId.uid ?? "Error (uid)"); + } } }); // yarn test // If you sign out, reload app to sign back in as test user - // Moved outside of useEffect to avoid race condition with logout + // Moved outside of onAuthChanged to avoid race condition with logout if (process.env.EXPO_PUBLIC_TEST_UID) { setCurrentUserId(process.env.EXPO_PUBLIC_TEST_UID); } From 285d808ce7487b16c7f45aa3732ca72adbee45ce Mon Sep 17 00:00:00 2001 From: solderq35 Date: Tue, 2 Apr 2024 17:29:52 -0700 Subject: [PATCH 2/5] move if statement up --- context/Auth.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/context/Auth.js b/context/Auth.js index 7860f36f..5af5d67a 100644 --- a/context/Auth.js +++ b/context/Auth.js @@ -45,23 +45,21 @@ export const AuthProvider = ({ children }) => { useEffect(() => { //if this code is not in here, it'll run for infinite times onAuthStateChanged(auth, (currentUserId) => { - // keep this log outside if statement to confirm e.g. logout of test user console.log("user changed"); - // prevent "persistent login" of regular user login from conflicting with test user - if (!process.env.EXPO_PUBLIC_TEST_UID) { + // test user login (yarn test) + // If you sign out, reload app to sign back in as test user + if (process.env.EXPO_PUBLIC_TEST_UID) { + setCurrentUserId(process.env.EXPO_PUBLIC_TEST_UID); + } + + // regular user login + else { if (currentUserId) { setCurrentUserId(currentUserId.uid ?? "Error (uid)"); } } }); - - // yarn test - // If you sign out, reload app to sign back in as test user - // Moved outside of onAuthChanged to avoid race condition with logout - if (process.env.EXPO_PUBLIC_TEST_UID) { - setCurrentUserId(process.env.EXPO_PUBLIC_TEST_UID); - } }, []); return ( Date: Tue, 2 Apr 2024 19:50:18 -0700 Subject: [PATCH 3/5] test login button --- .env.test => .env.development | 0 README.md | 11 ++--------- app/(auth)/signin.js | 25 +++++++++++++++++++++++++ context/Auth.js | 15 +++------------ package.json | 2 -- yarn.lock | 9 +-------- 6 files changed, 31 insertions(+), 31 deletions(-) rename .env.test => .env.development (100%) diff --git a/.env.test b/.env.development similarity index 100% rename from .env.test rename to .env.development diff --git a/README.md b/README.md index c706b932..5ff50beb 100644 --- a/README.md +++ b/README.md @@ -76,15 +76,8 @@ Info below subject to change ### Login Bypass -- `yarn test` - - Bypass login for testing purposes, will log you in as a dummy user "John Doe" - - If you logged out of app, reload / restart app to automatically log back in as dummy user - - Optional arguments: - - `--tunnel` - - For WiFi tunneling as described above - - `--ios` or `--android` - - For running app on iOS or Android emulator - - Note that arguments can be combined, e.g. `yarn test --android --tunnel` +- Press the "Test Login" button on the SignIn page +- NOTE: Current implementation does not have persistent storage for the test user, if you reload or restart the server you need to press the "Test Login" button again (assuming you wanted to stay signed in as test user) ### Formatting Script diff --git a/app/(auth)/signin.js b/app/(auth)/signin.js index 97a28756..7b1ae088 100644 --- a/app/(auth)/signin.js +++ b/app/(auth)/signin.js @@ -16,6 +16,7 @@ import { View, } from "react-native"; import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"; +import { currentAuthContext } from "~/context/Auth"; import { auth } from "~/firebaseConfig"; const BUTTON_WIDTH = 150; @@ -24,6 +25,7 @@ const INPUT_WIDTH = 200; export default function SignIn() { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); + const { setCurrentUserId } = currentAuthContext(); async function handleSignIn() { try { @@ -39,6 +41,20 @@ export default function SignIn() { } } + async function handleTestSignIn() { + try { + // Check the env var exists just in case. + // I put the test uid in an .env file to make it easier to change if we ever need to call it elsewhere, otherwise + // this could be hardcoded. + if (process.env.EXPO_PUBLIC_TEST_UID) { + setCurrentUserId(process.env.EXPO_PUBLIC_TEST_UID); + } + } catch (e) { + alert(e); + console.log(e); + } + } + async function handleForgotPassword() { try { if (email === "") { @@ -110,6 +126,15 @@ export default function SignIn() { > Login + + + Test Login + + Sign Up diff --git a/context/Auth.js b/context/Auth.js index 5af5d67a..62ab3698 100644 --- a/context/Auth.js +++ b/context/Auth.js @@ -46,18 +46,9 @@ export const AuthProvider = ({ children }) => { //if this code is not in here, it'll run for infinite times onAuthStateChanged(auth, (currentUserId) => { console.log("user changed"); - - // test user login (yarn test) - // If you sign out, reload app to sign back in as test user - if (process.env.EXPO_PUBLIC_TEST_UID) { - setCurrentUserId(process.env.EXPO_PUBLIC_TEST_UID); - } - - // regular user login - else { - if (currentUserId) { - setCurrentUserId(currentUserId.uid ?? "Error (uid)"); - } + console.log(currentUserId); + if (currentUserId) { + setCurrentUserId(currentUserId.uid ?? "Error (uid)"); } }); }, []); diff --git a/package.json b/package.json index cc37048f..8198f636 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "main": "expo-router/entry", "scripts": { "start": "expo start", - "test": "cross-env NODE_ENV=test expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web", @@ -19,7 +18,6 @@ "@react-native-async-storage/async-storage": "^1.22.3", "@tanstack/react-query": "^5.24.1", "babel-plugin-root-import": "^6.6.0", - "cross-env": "^7.0.3", "d3-scale": "^4.0.2", "d3-shape": "^3.2.0", "expo": "~49.0.15", diff --git a/yarn.lock b/yarn.lock index e821eb4a..fe64e1c4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4228,13 +4228,6 @@ cosmiconfig@^5.0.5, cosmiconfig@^5.1.0: js-yaml "^3.13.1" parse-json "^4.0.0" -cross-env@^7.0.3: - version "7.0.3" - resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf" - integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw== - dependencies: - cross-spawn "^7.0.1" - cross-fetch@^3.1.5: version "3.1.8" resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.8.tgz#0327eba65fd68a7d119f8fb2bf9334a1a7956f82" @@ -4253,7 +4246,7 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5: shebang-command "^1.2.0" which "^1.2.9" -cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.3: +cross-spawn@^7.0.0, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== From f9534274cc47c4bcc1e042f24958d2f0e61d972b Mon Sep 17 00:00:00 2001 From: solderq35 Date: Wed, 3 Apr 2024 14:13:11 -0700 Subject: [PATCH 4/5] revert to 285d808 (undo button commit) --- .env.development => .env.test | 0 README.md | 11 +++++++++-- app/(auth)/signin.js | 25 ------------------------- context/Auth.js | 15 ++++++++++++--- package.json | 2 ++ yarn.lock | 9 ++++++++- 6 files changed, 31 insertions(+), 31 deletions(-) rename .env.development => .env.test (100%) diff --git a/.env.development b/.env.test similarity index 100% rename from .env.development rename to .env.test diff --git a/README.md b/README.md index 5ff50beb..c706b932 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,15 @@ Info below subject to change ### Login Bypass -- Press the "Test Login" button on the SignIn page -- NOTE: Current implementation does not have persistent storage for the test user, if you reload or restart the server you need to press the "Test Login" button again (assuming you wanted to stay signed in as test user) +- `yarn test` + - Bypass login for testing purposes, will log you in as a dummy user "John Doe" + - If you logged out of app, reload / restart app to automatically log back in as dummy user + - Optional arguments: + - `--tunnel` + - For WiFi tunneling as described above + - `--ios` or `--android` + - For running app on iOS or Android emulator + - Note that arguments can be combined, e.g. `yarn test --android --tunnel` ### Formatting Script diff --git a/app/(auth)/signin.js b/app/(auth)/signin.js index 7b1ae088..97a28756 100644 --- a/app/(auth)/signin.js +++ b/app/(auth)/signin.js @@ -16,7 +16,6 @@ import { View, } from "react-native"; import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"; -import { currentAuthContext } from "~/context/Auth"; import { auth } from "~/firebaseConfig"; const BUTTON_WIDTH = 150; @@ -25,7 +24,6 @@ const INPUT_WIDTH = 200; export default function SignIn() { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); - const { setCurrentUserId } = currentAuthContext(); async function handleSignIn() { try { @@ -41,20 +39,6 @@ export default function SignIn() { } } - async function handleTestSignIn() { - try { - // Check the env var exists just in case. - // I put the test uid in an .env file to make it easier to change if we ever need to call it elsewhere, otherwise - // this could be hardcoded. - if (process.env.EXPO_PUBLIC_TEST_UID) { - setCurrentUserId(process.env.EXPO_PUBLIC_TEST_UID); - } - } catch (e) { - alert(e); - console.log(e); - } - } - async function handleForgotPassword() { try { if (email === "") { @@ -126,15 +110,6 @@ export default function SignIn() { > Login - - - Test Login - - Sign Up diff --git a/context/Auth.js b/context/Auth.js index 62ab3698..5af5d67a 100644 --- a/context/Auth.js +++ b/context/Auth.js @@ -46,9 +46,18 @@ export const AuthProvider = ({ children }) => { //if this code is not in here, it'll run for infinite times onAuthStateChanged(auth, (currentUserId) => { console.log("user changed"); - console.log(currentUserId); - if (currentUserId) { - setCurrentUserId(currentUserId.uid ?? "Error (uid)"); + + // test user login (yarn test) + // If you sign out, reload app to sign back in as test user + if (process.env.EXPO_PUBLIC_TEST_UID) { + setCurrentUserId(process.env.EXPO_PUBLIC_TEST_UID); + } + + // regular user login + else { + if (currentUserId) { + setCurrentUserId(currentUserId.uid ?? "Error (uid)"); + } } }); }, []); diff --git a/package.json b/package.json index 8198f636..cc37048f 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "main": "expo-router/entry", "scripts": { "start": "expo start", + "test": "cross-env NODE_ENV=test expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web", @@ -18,6 +19,7 @@ "@react-native-async-storage/async-storage": "^1.22.3", "@tanstack/react-query": "^5.24.1", "babel-plugin-root-import": "^6.6.0", + "cross-env": "^7.0.3", "d3-scale": "^4.0.2", "d3-shape": "^3.2.0", "expo": "~49.0.15", diff --git a/yarn.lock b/yarn.lock index fe64e1c4..e821eb4a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4228,6 +4228,13 @@ cosmiconfig@^5.0.5, cosmiconfig@^5.1.0: js-yaml "^3.13.1" parse-json "^4.0.0" +cross-env@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf" + integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw== + dependencies: + cross-spawn "^7.0.1" + cross-fetch@^3.1.5: version "3.1.8" resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.8.tgz#0327eba65fd68a7d119f8fb2bf9334a1a7956f82" @@ -4246,7 +4253,7 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5: shebang-command "^1.2.0" which "^1.2.9" -cross-spawn@^7.0.0, cross-spawn@^7.0.3: +cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== From 22d0c56f53234a4f042fda91643d53c5adabf236 Mon Sep 17 00:00:00 2001 From: solderq35 Date: Wed, 3 Apr 2024 14:15:21 -0700 Subject: [PATCH 5/5] add comment for reference --- babel.config.js | 9 +++++++++ package.json | 1 + yarn.lock | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/babel.config.js b/babel.config.js index d3fd24ad..0c705bff 100644 --- a/babel.config.js +++ b/babel.config.js @@ -3,7 +3,16 @@ module.exports = function (api) { return { presets: ["babel-preset-expo", "module:metro-react-native-babel-preset"], plugins: [ + // Fix issues with test login script (yarn test), and build cache + // Reference: https://github.com/expo/router/issues/41#issuecomment-1657674119 + [ + "transform-inline-environment-variables", + { + include: ["EXPO_ROUTER_APP_ROOT"], + }, + ], require.resolve("expo-router/babel"), + "@babel/plugin-transform-export-namespace-from", "react-native-paper/babel", "react-native-reanimated/plugin", [ diff --git a/package.json b/package.json index cc37048f..27dda396 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "devDependencies": { "@babel/core": "^7.20.0", "@tanstack/eslint-plugin-query": "^5.20.1", + "babel-plugin-transform-inline-environment-variables": "^0.4.4", "prettier": "3.2.5", "prettier-plugin-organize-imports": "^3.2.4" }, diff --git a/yarn.lock b/yarn.lock index e821eb4a..2eedb787 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3523,6 +3523,11 @@ babel-plugin-transform-flow-enums@^0.0.2: dependencies: "@babel/plugin-syntax-flow" "^7.12.1" +babel-plugin-transform-inline-environment-variables@^0.4.4: + version "0.4.4" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-inline-environment-variables/-/babel-plugin-transform-inline-environment-variables-0.4.4.tgz#974245008b3cbbd646bd81707af147aea3acca43" + integrity sha512-bJILBtn5a11SmtR2j/3mBOjX4K3weC6cq+NNZ7hG22wCAqpc3qtj/iN7dSe9HDiS46lgp1nHsQgeYrea/RUe+g== + babel-preset-expo@~9.5.2: version "9.5.2" resolved "https://registry.yarnpkg.com/babel-preset-expo/-/babel-preset-expo-9.5.2.tgz#5ed1756c8434ca972d7a940e4f13570a283641df"