From f9534274cc47c4bcc1e042f24958d2f0e61d972b Mon Sep 17 00:00:00 2001 From: solderq35 Date: Wed, 3 Apr 2024 14:13:11 -0700 Subject: [PATCH] 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==