Skip to content

Commit

Permalink
Merge branch 'frankreed/foreignManagement8_debouncin' into frankreed/…
Browse files Browse the repository at this point in the history
…foreignManagement9_status_snackbar
  • Loading branch information
FrankreedX committed Aug 15, 2024
2 parents 6e29e4c + 90a4e20 commit 5b24b7d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
11 changes: 10 additions & 1 deletion Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const themeColors = {
highlight: "#fff",
};

const TESTING = true;

const prettyTitle = {
target: "Target",
sideLanding: "Side Landing",
Expand Down Expand Up @@ -55,4 +57,11 @@ const firebaseErrors = {
"auth/missing-email": "Missing email",
"auth/missing-password": "Missing password",
};
export { firebaseErrors, prettyRole, prettyTitle, shortTitle, themeColors };
export {
TESTING,
firebaseErrors,
prettyRole,
prettyTitle,
shortTitle,
themeColors,
};
4 changes: 2 additions & 2 deletions app/(auth)/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from "react-native";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import { Button } from "react-native-paper";
import { themeColors } from "~/Constants";
import { TESTING, themeColors } from "~/Constants";
import { getErrorString } from "~/Utility";
import ProfilePicture from "~/components/ProfilePicture";
import { useAlertContext } from "~/context/Alert";
Expand Down Expand Up @@ -48,7 +48,7 @@ export default function SignUp() {
if (password !== passwordCheck) {
throw "Passwords don't match";
}
if (!email.endsWith("@oregonstate.edu")) {
if (!TESTING && !email.endsWith("@oregonstate.edu")) {
throw "Only @oregonstate.edu emails are allowed at this time.";
}
const userCredential = await createUserWithEmailAndPassword(
Expand Down
6 changes: 5 additions & 1 deletion app/segments/(team)/chooseTeam.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
import { RefreshControl, ScrollView, Text, View } from "react-native";
import { Button } from "react-native-paper";
import { SafeAreaView } from "react-native-safe-area-context";
import { themeColors } from "~/Constants";
import { TESTING, themeColors } from "~/Constants";
import { getErrorString } from "~/Utility";
import ErrorComponent from "~/components/errorComponent";
import Loading from "~/components/loading";
Expand Down Expand Up @@ -98,6 +98,10 @@ function ChooseTeam() {
}

useEffect(() => {
if (TESTING) {
setVerified(true);
return;
}
const unregisterAuthObserver = onIdTokenChanged(auth, async (user) => {
if (user) {
if (user.emailVerified) {
Expand Down
2 changes: 2 additions & 0 deletions context/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export const AlertProvider = ({ children }) => {

const [snackbarVisible, setSnackbarVisible] = useState(false);
const [snackbarMessage, setSnackbarMessage] = useState("");

return (
<AlertContext.Provider
value={{
showDialog: (title, message) => {
if (title === "Error" && message === "permission-denied") return; //for initial sign in. do this or change the rules
setDialogTitle(title);
setDialogMessage(message);
setDialogVisible(true);
Expand Down
8 changes: 7 additions & 1 deletion context/Auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useRouter, useSegments } from "expo-router";
import { onIdTokenChanged } from "firebase/auth";
import { createContext, useContext, useEffect, useState } from "react";
import { TESTING } from "~/Constants";
import { auth } from "~/firebaseConfig";

const AuthContext = createContext({
Expand Down Expand Up @@ -57,7 +58,12 @@ export const AuthProvider = ({ children }) => {
setCurrentUserId(newlyLoggedInUser["uid"] ?? "Error (uid)");
setCurrentUserInfo(newlyLoggedInUser ?? {});
console.log("user changed. userId:", newlyLoggedInUser["uid"]);
setCurrentUserVerified(auth.currentUser.emailVerified);

if (TESTING) {
setCurrentUserVerified(true);
} else {
setCurrentUserVerified(auth.currentUser.emailVerified);
}
}
}
});
Expand Down
21 changes: 17 additions & 4 deletions dbOperations/hooks/useUserInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "firebase/firestore";
import { useAuthContext } from "~/context/Auth";
import { db } from "~/firebaseConfig";
import { getErrorString } from "~/Utility";

export const useUserInfo = ({
userId = null,
Expand All @@ -29,11 +30,23 @@ export const useUserInfo = ({
queryFn: async () => {
console.log("fetching userInfo: ", { userId, role });
if (userId) {
const querySnapshot = await getDoc(
doc(db, "teams", currentTeamId, "users", userId),
);
const data = querySnapshot.data();
let data;
try {
const querySnapshot = await getDoc(
doc(db, "teams", currentTeamId, "users", userId),
);
data = querySnapshot.data();
} catch (e) {
if (getErrorString(e) === "permission-denied") {
data = undefined;
} else {
throw e;
}
console.log("e", getErrorString(e));
}

const inChooseTeam = segments.at(-1) === "chooseTeam";

if (!data || !currentUserVerified) {
if (currentUserId === userId && !inChooseTeam) {
router.replace("segments/(team)/chooseTeam");
Expand Down

0 comments on commit 5b24b7d

Please sign in to comment.