-
-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: toast import and add readable feedback to the user when Google Auth fails #810
Conversation
👷 Deploy request for digitomize pending review.Visit the deploys page to approve it
|
👷 Deploy request for v2-digitomize pending review.Visit the deploys page to approve it
|
WalkthroughThe recent update introduces enhanced error handling in the Google authentication process application-wide. It incorporates Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const onError = (firebaseError)=>{ | ||
setError("Failed to sign-in with Gmail"); | ||
toast.error(firebaseError.code, { | ||
position: "top-right", | ||
autoClose: 5000, | ||
hideProgressBar: false, | ||
closeOnClick: true, | ||
pauseOnHover: true, | ||
draggable: true, | ||
progress: undefined, | ||
theme: "colored", | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider enhancing the user-friendliness of error messages.
- toast.error(firebaseError.code, {
+ toast.error(`An error occurred: ${firebaseError.message}`, {
This change uses the error message instead of the error code, which is generally more descriptive and user-friendly.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
const onError = (firebaseError)=>{ | |
setError("Failed to sign-in with Gmail"); | |
toast.error(firebaseError.code, { | |
position: "top-right", | |
autoClose: 5000, | |
hideProgressBar: false, | |
closeOnClick: true, | |
pauseOnHover: true, | |
draggable: true, | |
progress: undefined, | |
theme: "colored", | |
}); | |
} | |
const onError = (firebaseError)=>{ | |
setError("Failed to sign-in with Gmail"); | |
toast.error(`An error occurred: ${firebaseError.message}`, { | |
position: "top-right", | |
autoClose: 5000, | |
hideProgressBar: false, | |
closeOnClick: true, | |
pauseOnHover: true, | |
draggable: true, | |
progress: undefined, | |
theme: "colored", | |
}); | |
} |
.catch((err) =>onError(err)); | ||
}); | ||
navigate("/u/dashboard"); | ||
}) | ||
.catch((err) => { | ||
setError(err.code); | ||
toast.error(error.code, { | ||
position: "top-right", | ||
autoClose: 5000, | ||
hideProgressBar: false, | ||
closeOnClick: true, | ||
pauseOnHover: true, | ||
draggable: true, | ||
progress: undefined, | ||
theme: "colored", | ||
}); | ||
onError(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor to use async/await consistently for better readability and error handling.
- .then(async () => {
- await auth.currentUser.getIdToken(true).then(async (idToken) => {
- await axios
- .post(`${backendUrl}/user/signup`, {
- headers: {
- Authorization: `Bearer ${idToken}`,
- },
- })
- .catch((err) =>onError(err));
- });
- navigate("/u/dashboard");
- })
- .catch((err) => {
- onError(err);
- });
+ try {
+ await signInWithPopup(auth, googleAuthProvider);
+ const idToken = await auth.currentUser.getIdToken(true);
+ try {
+ await axios.post(`${backendUrl}/user/signup`, {
+ headers: {
+ Authorization: `Bearer ${idToken}`,
+ },
+ });
+ navigate("/u/dashboard");
+ } catch (err) {
+ onError(err);
+ }
+ } catch (err) {
+ onError(err);
+ }
This refactoring removes the nested .then()
and .catch()
blocks, replacing them with a more readable and maintainable structure using async/await
.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
.catch((err) =>onError(err)); | |
}); | |
navigate("/u/dashboard"); | |
}) | |
.catch((err) => { | |
setError(err.code); | |
toast.error(error.code, { | |
position: "top-right", | |
autoClose: 5000, | |
hideProgressBar: false, | |
closeOnClick: true, | |
pauseOnHover: true, | |
draggable: true, | |
progress: undefined, | |
theme: "colored", | |
}); | |
onError(err); | |
try { | |
await signInWithPopup(auth, googleAuthProvider); | |
const idToken = await auth.currentUser.getIdToken(true); | |
try { | |
await axios.post(`${backendUrl}/user/signup`, { | |
headers: { | |
Authorization: `Bearer ${idToken}`, | |
}, | |
}); | |
navigate("/u/dashboard"); | |
} catch (err) { | |
onError(err); | |
} | |
} catch (err) { | |
onError(err); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- client/src/components/AuthButtons/GoogleAuthButton.jsx (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- client/src/components/AuthButtons/GoogleAuthButton.jsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- client/src/components/AuthButtons/GoogleAuthButton.jsx (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- client/src/components/AuthButtons/GoogleAuthButton.jsx
Please do the formatting (using prettier) |
This pull request did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please verify it has no conflicts with the develop branch and rebase if needed. Mention it now if you need help or give permission to other people to finish your work. |
Inactive PR |
fix the toast import error, improve the structure of the code, and display an appropriate error message when the Google Auth fails.
Summary by CodeRabbit