Skip to content

Commit

Permalink
removed unnecessary console.log statements
Browse files Browse the repository at this point in the history
  • Loading branch information
nkanchinadam committed Sep 18, 2024
1 parent d2e3e22 commit cf49b61
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 79 deletions.
4 changes: 2 additions & 2 deletions src/app/api/auth/claims/registering/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
}
return NextResponse.json({ error: "Role already set" }, { status: 400 });
} catch (err) {
console.error(err);
return NextResponse.json({ error: err }, { status: 500 });
console.error("unable to set role");
return NextResponse.json({ error: "unable to set role" }, { status: 500 });
}
}
4 changes: 2 additions & 2 deletions src/app/api/auth/claims/student/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
}
return NextResponse.json({ error: "Role already set" }, { status: 400 });
} catch (err) {
console.error(err);
return NextResponse.json({ error: err }, { status: 500 });
console.error("unable to set role");
return NextResponse.json({ error: "unable to set role" }, { status: 500 });
}
}
1 change: 0 additions & 1 deletion src/app/api/auth/handler/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { isRefreshTokenValid, setAdminRefreshToken } from "@/lib/googleAuthoriza
export async function GET(req: NextRequest) {
const query = req.nextUrl.searchParams;
if (query.get("code")) {
console.log(query.get("code"));
const authCode = query.get("code") || "";
const updateNeeded = !(await isRefreshTokenValid());
if (updateNeeded) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/email/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function POST(req: NextRequest) {
await sendEmail({ recipients, subject, text });
return NextResponse.json({ message: 'Emails successfully sent' }, { status: 200 });
} catch (err) {
console.error("Error in POST request:", err);
console.error("Error sending email");
return NextResponse.json({ error: 'Error sending email' }, { status: 500 });
}
}
2 changes: 1 addition & 1 deletion src/app/api/googleForms/surveys/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function POST(req: NextRequest) {
};
return NextResponse.json(form, { status: 200 })
} catch (err) {
console.log(err);
console.log("error creating survey");
return NextResponse.json(
{ error: "error creating survey" },
{ status: 500 }
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/watches/handler/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function POST(req: NextRequest) {
}
return NextResponse.json({ message: "watch event successfully handled" }, { status: 200 });
} catch (err) {
console.log(err);
console.log("unable to handle watch event");
return NextResponse.json({ error: "unable to handle watch event" }, { status: 500 });
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/watches/renewAll/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function POST(req: NextRequest) {
});
return NextResponse.json({ message: "all watches renewed"}, { status: 200 });
} catch (err) {
console.error(err);
console.error("error renewing all watches");
return NextResponse.json({ error: 'error renewing all watches' }, { status: 500 });
}
}
5 changes: 1 addition & 4 deletions src/app/create-account/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ export default function CreateAccountPage() {

const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
console.log("Submitting:", accountInfo);
try {
if (auth.currentUser?.uid === undefined) {
throw Error("Failed to create account")
Expand Down Expand Up @@ -323,8 +322,6 @@ export default function CreateAccountPage() {
// Update metadata with new SwaligaID
await setDoc(doc(db, 'metadata', 'nextUserId'), { nextUserId: newSwaligaID });

console.log("Account created successfully:", user);

// Set role to STUDENT via API
await fetch("/api/auth/claims/student", {
method: "POST",
Expand All @@ -341,7 +338,7 @@ export default function CreateAccountPage() {
router.push("/student-dashboard");

} catch (error) {
console.error("Error during account creation:", error);
console.error("Error during account creation");
setFormError("Unexpected error occurred");
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/reset-password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function ResetPasswordPage() {
setMessage("Check your email to reset password");
} catch (error) {
setError("Email not found");
console.error("Error resetting password:", error);
console.error("Error resetting password");
}
};

Expand Down
5 changes: 2 additions & 3 deletions src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function Settings() {
const userData = await getAccountById(id);
setUserData(userData);
} catch (error) {
console.error("Error fetching user data:", error);
console.error("Error fetching user data");
}
setLoading(false);
};
Expand All @@ -47,10 +47,9 @@ export default function Settings() {
await updateAccount(userData?.id as string, {
...userData
});
console.log("User data updated successfully");
router.push("/student-dashboard"); // Redirect to student dashboard
} catch (error) {
console.error("Error updating user data:", error);
console.error("Error updating user data");
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/app/student-dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ export default function StudentDashboard() {
useEffect(() => {
onAuthStateChanged(auth, async (currentUser) => {
setLoading(true);
console.log(currentUser);
if (currentUser) {
await fetchCurrentUserData(currentUser.uid);
console.log(currentUser.uid);
} else {
console.log("No signed-in user");
console.error("No signed-in user");
}
setLoading(false);
});
Expand All @@ -55,9 +53,8 @@ export default function StudentDashboard() {
setResponses(responses.filter(response => response).map(response => response!.formTitle));
})
} catch (error) {
console.error(error);
console.log('ERROR', auth.currentUser);
throw new Error('unable to fetch data for student dashboard');
console.error("unable to load student dashboard");
throw new Error("unable to load student dashboard");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/user/[userId]/StudentInfoPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default function StudentInfoPage({
setSurveys(surveys.filter(survey => survey) as Survey[]);
})
} catch (err) {
console.log("Error retrieving student information using given userId");
console.error("Error retrieving student information");
}
setLoading(false);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Assign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function Assign({ studentIds, surveys, closeAssign }: AssignProps
await assignSurveys(studentIds, selectedSurveyIds);
closeAssign();
} catch (error) {
console.error("Error occurred while assigning surveys:", error);
console.error("unable to assign surveys");
setError("unable to assign surveys")
}
};
Expand Down
2 changes: 0 additions & 2 deletions src/components/auth/RequireStudentAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { Role } from '@/types/user-types';

export default function RequireStudentAuth({ children }: { children: JSX.Element }): JSX.Element {
const authContext = useAuth();
console.log(authContext.token?.claims.role === Role.STUDENT)
console.log(authContext);
if (authContext.loading) {
return <p>Loading</p>
} else if (!authContext.user) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function Create({ closeCreate }: CreateProps) {
createSurvey(surveyTitle);
closeCreate();
} catch (error) {
console.error("Error occurred while creating survey:", error);
console.error("Error creating survey");
setError("Error creating survey");
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const signUpUser = async (
await auth.currentUser?.getIdToken(true);
return { success: true, userId: userUid };
} catch (error) {
console.log(error);
console.error("unable to sign up");
return { success: false, userId: null };
}
};
Expand All @@ -60,7 +60,7 @@ export const loginUser = async (
const user = userCredential.user;
return { success: true, userId: user.uid };
} catch (error) {
console.log(error);
console.error("unable to log in");
return { success: false, userId: null };
}
};
18 changes: 3 additions & 15 deletions src/lib/firebase/authentication/googleAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ async function verifyGoogleToken(googleAccessToken: string | undefined): Promise
const data = await response.json();

if (data.error) {
console.error("Invalid Token", data.error);
console.error("Invalid Token");
return false;
} else {
console.log("Token is valid", data);
console.log("Token is valid");
return true;
}
}
Expand All @@ -35,11 +35,6 @@ async function signInWithGoogle(router: AppRouterInstance): Promise<void> {
const accessToken = credential?.accessToken;
const verified = await verifyGoogleToken(accessToken);

if (!verified) {
console.log("Please sign in again");
return;
}

// Get the current user's ID token result to check custom claims
const idTokenResult = await auth.currentUser?.getIdTokenResult();
const role: Role | undefined = idTokenResult?.claims.role as (Role | undefined);
Expand Down Expand Up @@ -70,21 +65,14 @@ async function signInWithGoogle(router: AppRouterInstance): Promise<void> {
break;
}
} catch (error: unknown) {
if ((error as FirebaseError).code === 'auth/account-exists-with-different-credential') {
console.log("Account exists with different credential.");
} else {
console.error("Error during Google sign-in:", error);
}
console.error("unable to sign in with Google")
}
}

async function logOut(): Promise<void> {
const user = auth.currentUser;
if (user) {
await auth.signOut();
console.log("Sign-out successful");
} else {
console.log("No user is signed in");
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/lib/firebase/database/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export async function getResponseByID(
return null;
}
} catch (error) {
console.error("Error getting response by ID:", error);
throw new Error("unable to get response by id");
console.error("unable to get response");
throw new Error("unable to get response");
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/lib/firebase/database/surveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function createSurvey(title: string) {
await setDoc(doc(db, "surveys", form!.formId || ""), form);
return form;
} catch (err) {
console.log(err);
console.error("unable to create survey");
throw Error('unable to create survey');
}
}
Expand All @@ -33,7 +33,7 @@ export async function getAllSurveys() {
const allSurveys: Survey[] = surveySnapshot.docs.map((doc) => doc.data() as Survey);
return allSurveys;
} catch (error) {
console.error('unable to get all surveys');
console.error('unable to get surveys');
throw new Error('unable to get surveys');
}
}
Expand All @@ -58,7 +58,7 @@ export async function deleteSurveyByID(surveyId: string) {
await deleteDoc(doc(db, "surveys", surveyId));
});
} catch (err) {
console.log(err);
console.log("unable to delete survey");
throw Error('unable to delete survey');
}
}
28 changes: 7 additions & 21 deletions src/lib/firebase/database/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,34 @@ export async function getAccountById(id: string): Promise<User> {
const docRef = doc(db, "users", id);
const snapshot = await getDoc(docRef);
if (snapshot.exists()) {
console.log("Retrieved account successfully");
return snapshot.data() as User;
} else {
console.log("Account or id doesn't exist");
console.error("Account or id doesn't exist");
throw new Error("Account or id doesn't exist");
}
} catch (error) {
console.error("Error with retrieving account by id: ", error);
throw error;
console.error("unable to get account");
throw new Error("unable to get account");
}
}

export async function createAccount(user: User): Promise<void> {
try {
console.log("Attempting to create account: ", user);
const usersCollectionRef = collection(db, "users");
const docRef = await addDoc(usersCollectionRef, user);
console.log("Account created successfully with ID: ", docRef.id);
} catch (error) {
console.error("Error creating account:", error);
throw error;
console.error("Error creating account");
throw new Error("Error creating account");
}
}

export async function updateAccount(id: string, updatedUserData: UpdateData<User>): Promise<void> {
try {
const user = doc(db, "users", id);
await updateDoc(user, updatedUserData);
console.log("Account updated successfully");
} catch (error) {
console.error("Error updating account:", error);
throw error;
console.error("Error updating account:");
throw new Error("Error updating account");
}
}

Expand Down Expand Up @@ -68,10 +64,6 @@ export async function assignSurveys(
await updateDoc(userRef, {
assignedSurveys: arrayUnion(...surveyIds),
});

console.log(`Surveys ${surveyIds} assigned to User ${userId}`);
// If user already added don't do nothing/remove..
// TODO Make this both ways...get this done by tomorrow.
}

// Assign a list of students to a list of surveys
Expand All @@ -80,8 +72,6 @@ export async function assignSurveys(
await updateDoc(surveyRef, {
assignedUsers: arrayUnion(...userIds),
});

console.log(`Users ${userIds} assigned to Survey ${surveyId}`);
}
}

Expand All @@ -95,8 +85,6 @@ export async function unassignSurveys(
await updateDoc(userRef, {
assignedSurveys: arrayRemove(...surveyIds),
});

console.log(`Surveys ${surveyIds} removed from User ${userId}`);
}

// Unassign a list of students from a list of surveys
Expand All @@ -105,7 +93,5 @@ export async function unassignSurveys(
await updateDoc(surveyRef, {
assignedUsers: arrayRemove(...userIds),
});

console.log(`Users ${userIds} removed from Survey ${surveyId}`);
}
}
11 changes: 4 additions & 7 deletions src/lib/firebase/database/watches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export async function createWatch(formId: string, eventType: string) {

return response.data;
} catch (error) {
console.log("Error with creating watch using given information", error);
throw error;
console.error("Error with creating watch");
throw new Error("Error with creating watch");
}
}

Expand All @@ -39,10 +39,7 @@ export async function renewWatch(formId: string, watchId: string) {
}
return watch;
} catch (error) {
console.log(
"Error with renewing watch using given formId and watchId",
error
);
throw error;
console.error("Unable to renew watch");
throw new Error("Unable to renew watch");
}
}
Loading

0 comments on commit cf49b61

Please sign in to comment.