Skip to content

Commit

Permalink
Fixed a bug related to DP uploads and in Leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
sikehish committed Jun 10, 2024
1 parent 543284d commit 2939cb5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
7 changes: 4 additions & 3 deletions backend/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ export const uploadImage = asyncWrapper(async (req, res) => {
//Handle Optional fields(on signup)
export const handleOptionalFields = asyncWrapper(async (req, res) => {
let { email, description } = req.body;
console.log("HAHAHAHAH ", email, description)

if(!email){
res.status(400);
Expand All @@ -520,9 +521,9 @@ export const handleOptionalFields = asyncWrapper(async (req, res) => {
runValidators: true
});
}


const imageData = req?.file?.buffer.toString("base64");
const imageData = req?.file?.buffer.toString("base64");
console.log("HAHA: ",description, imageData)
if (imageData) {
await redisClient.set(existingUser._id, imageData);
}
Expand Down
15 changes: 9 additions & 6 deletions frontend/src/pages/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ function Login() {


const googleAuth = (e: any) => {
e.preventDefault()
window.open(
`/api/oauth/google/callback`,
"_self"
);
};
e.preventDefault();
const callbackUrl =
import.meta.env.VITE_NODE_ENV === "development"
? "http://localhost:3000/api/oauth/google/callback"
: "/api/oauth/google/callback";

window.open(callbackUrl, "_self");
};

// // OR //--> The below is returning undefined in Elastic Beanstalk
// const googleAuth = (e: any) => {
// e.preventDefault()
Expand Down
40 changes: 23 additions & 17 deletions frontend/src/pages/auth/Signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ function Signup() {
const queryClient=useQueryClient()

const googleAuth = (e: any) => {
e.preventDefault()
window.open(
`/api/oauth/google/callback`,
"_self"
);
};
e.preventDefault();
const callbackUrl =
import.meta.env.VITE_NODE_ENV === "development"
? "http://localhost:3000/api/oauth/google/callback"
: "/api/oauth/google/callback";

window.open(callbackUrl, "_self");
};
// // OR
// const googleAuth = (e: any) => {
// e.preventDefault()
Expand All @@ -49,18 +51,18 @@ function Signup() {
if(typeof description === "string" && description.length && !description.trim()){
throw new Error("Ensure that the description you enter isnt an empty string!");
}

const formData = new FormData();

formData.append("email", email);

if (description || profilePicture) {
if (typeof description === "string" && description.trim()) {
formData.append("description", description.trim());
}

if (profilePicture) {
formData.append("profilePicture", profilePicture);
formData.append("avatar", profilePicture);
}
} else {
throw new Error("Data has to be entered for it to be saved :P");
Expand All @@ -70,12 +72,16 @@ function Signup() {
method: "PATCH",
body: formData,
});

const res=await response.json()

if (!response.ok) {
throw new Error("Failed to update optional fields");
if (!response.ok || res.status==="error") {
if(res.status=="error") throw new Error(res.message)
else throw new Error("Failed to update optional fields");
}

queryClient.invalidateQueries({ queryKey: ["current-user"] });
console.log("HHAAHHAHA ",email, description, profilePicture)
toast.success("Optional fields successfully updated!");
navigate("/login");
} catch (error) {
Expand Down Expand Up @@ -198,11 +204,11 @@ function Signup() {
{/* {isSucc && <div className="text-green-500 mb-4">Signup successful!</div>} */}

</div>
<span className="text-gray-400 mt-2">--- OR ---</span>
<button onClick={googleAuth} className="mt-2 mb-4 flex w-3/4 box-border bg-blue-600 px-3 py-2 rounded-full items-center justify-center">
{!showOptionalFields && <span className="text-gray-400 mt-2">--- OR ---</span>}
{!showOptionalFields && <button onClick={googleAuth} className="mt-2 mb-4 flex w-3/4 box-border bg-blue-600 px-3 py-2 rounded-full items-center justify-center">
<FaGoogle className="mr-2 text-white" />
<span className="text-white">Sign up with Google</span>
</button>
</button>}
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/user/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const Leaderboard = () => {
)}
<p className='mx-2'> {userRank?.data?.name}</p>
</div>
<p className='flex bg-blue-400 bg-opacity-20 px-3 py-1.5 rounded-xl shadow-md shadow-blue-400'><span className='text-lg'>{userRank?.data?.xp}</span> <Sparkles className="text-yellow-600 pl-1 fill-yellow-400" /></p>
</div>
</div>
)}
Expand Down

0 comments on commit 2939cb5

Please sign in to comment.