Skip to content
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

feat: User creation on register #272

Merged
merged 7 commits into from
May 2, 2024
Merged

feat: User creation on register #272

merged 7 commits into from
May 2, 2024

Conversation

Sanchitbajaj02
Copy link
Owner

@Sanchitbajaj02 Sanchitbajaj02 commented Apr 24, 2024

Related Issue

fixes #267

Description

changes pending for state and store handling

Summary by CodeRabbit

  • New Features

    • Enhanced registration process with improved user verification and data saving sequence.
    • Updated profile update functionalities with better error handling for image updates.
    • Added robust email validation and improved error handling in Forgot Password workflow.
    • Enhanced image upload capabilities in user profiles with support for modern image components.
  • Bug Fixes

    • Corrected navigation behavior in Forgot Password component.
    • Adjusted conditions for displaying confetti in the Verification component to ensure accuracy.
  • Style

    • Updated styling for like and comment interaction elements in posts for better user experience.
  • Documentation

    • Updated GitHub issue templates by refining labels for bug reports, documentation updates, feature requests, and style improvements.
  • Chores

    • Removed specific "SWOC S4" entries across various configurations and templates to streamline project management.
  • Refactor

    • Introduced a configuration in next.config.js to optimize the build process by ignoring ESLint checks during builds.

@Sanchitbajaj02 Sanchitbajaj02 self-assigned this Apr 24, 2024
Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
palettegram ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 2, 2024 6:10am

Copy link
Contributor

coderabbitai bot commented Apr 24, 2024

Walkthrough

The recent updates primarily focus on streamlining user management processes related to registration, password updates, and email verification. These changes aim to enhance validation, error handling, and database interactions for improved reliability and user experience. Navigation adjustments and more robust response checks have been implemented to refine the functionality of authentication components.

Changes

File Path Summary of Changes
src/backend/auth.api.ts - Enhanced user registration by adding a database save step.
- Reordered operations sequence and improved verification checks.
- Simplified password update validation.
src/backend/updateProfile.api.ts - Added error handling for missing image in saveImage function.
- Improved error handling in updateImageURL function.
src/components/core/posts/SinglePost.tsx - Adjusted class names and styles for liking and commenting on posts.
src/components/pages/auth/forgot/index.tsx - Enhanced email validation and error handling in ForgotComponent.
- Updated arrow icon navigation to direct to the home page.
src/components/pages/auth/updatepassword/index.tsx - Added response check in UpdatePasswordComponent to handle errors before redirection.
src/components/pages/auth/verification/index.tsx - Modified conditions for displaying confetti in VerificationComponent.
src/components/pages/user/imageUpload.tsx - Updated image handling with Next.js <Image> components and form submission.
- Improved error handling for missing images.
.github/ISSUE_TEMPLATE/bug.yml - Removed "SWOC S4" label from bug report template.
.github/ISSUE_TEMPLATE/docs.yml - Removed "SWOC S4" label from documentation issue template.
.github/ISSUE_TEMPLATE/feature.yml - Removed "SWOC S4" label from feature request template.
.github/ISSUE_TEMPLATE/styles.yml - Updated labels in styles issue template to remove "SWOC S4".
.github/labeler.yml - Removed specific entries related to "SWOC S4" in the labeler configuration.
next.config.js - Added configuration to ignore ESLint during builds.

Assessment against linked issues

Objective Addressed Explanation
Optimize user creation workflow (#267)

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 04080fe and a13101c.
Files selected for processing (4)
  • next.config.js (1 hunks)
  • src/backend/auth.api.ts (8 hunks)
  • src/components/pages/auth/forgot/index.tsx (2 hunks)
  • src/components/pages/auth/updatepassword/index.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • next.config.js
Files skipped from review as they are similar to previous changes (3)
  • src/backend/auth.api.ts
  • src/components/pages/auth/forgot/index.tsx
  • src/components/pages/auth/updatepassword/index.tsx

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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added wait for reviewers SWOC S4 Social Winter of Code (S4) 2024 contribution tag labels Apr 24, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, @Sanchitbajaj02! 🎉 Thank you for submitting your pull request. Your contribution is valuable and we appreciate your efforts to improve our project. Keep being the part of the community!

'We will promptly review your changes and offer feedback. Keep up the excellent work!
Kindly remember to check our Contributing Guidelines'

@github-actions github-actions bot added the title needs formatting Title of issue or pull request does not match the guidelines label Apr 24, 2024
@Sanchitbajaj02 Sanchitbajaj02 changed the title User creation on register feat: User creation on register Apr 24, 2024
@github-actions github-actions bot removed the title needs formatting Title of issue or pull request does not match the guidelines label Apr 24, 2024
@Sanchitbajaj02 Sanchitbajaj02 added 🪲 bug Something isn't working 🛠 goal: fix The label is related to fixing a bug ⭐ enhancement Feature enhancement MEDIUM Difficulty Level: Medium and removed wait for reviewers SWOC S4 Social Winter of Code (S4) 2024 contribution tag labels Apr 24, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Comment on lines 29 to 30
if (!email || email == "") {
throw new Error("Email not provided");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure robust email validation by checking for whitespace-only strings.

- if (!email || email == "") {
+ if (!email.trim()) {

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.

Suggested change
if (!email || email == "") {
throw new Error("Email not provided");
if (!email.trim()) {
throw new Error("Email not provided");

Comment on lines 35 to 37
if (!response) {
throw new Error("Err in sending email");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the error message is descriptive and user-friendly.

- throw new Error("Err in sending email");
+ throw new Error("Error occurred while sending the email. Please try again.");

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.

Suggested change
if (!response) {
throw new Error("Err in sending email");
}
if (!response) {
throw new Error("Error occurred while sending the email. Please try again.");
}

Comment on lines 43 to 45
if (!resp) {
throw new Error("Err in changing password");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the error message is clear and actionable for the user.

- throw new Error("Err in changing password");
+ throw new Error("Failed to update password. Please ensure your details are correct and try again.");

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.

Suggested change
if (!resp) {
throw new Error("Err in changing password");
}
if (!resp) {
throw new Error("Failed to update password. Please ensure your details are correct and try again.");
}

Comment on lines 96 to 106
if (!currentUser) {
throw new Error("Current user might be corrupted");
}

const result = db.updateDocument(palettegramDB, usersCollection, currentUser.documents[0].$id, {
isVerified: true,
});

if (!result) {
throw new Error("Error in verifying user");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate that the error handling is robust and the error messages are informative.

- throw new Error("Current user might be corrupted");
+ throw new Error("Failed to retrieve current user data. Please verify the user ID and database status.");
- throw new Error("Error in verifying user");
+ throw new Error("Failed to update user verification status. Please check the database operation.");

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.

Suggested change
if (!currentUser) {
throw new Error("Current user might be corrupted");
}
const result = db.updateDocument(palettegramDB, usersCollection, currentUser.documents[0].$id, {
isVerified: true,
});
if (!result) {
throw new Error("Error in verifying user");
}
if (!currentUser) {
throw new Error("Failed to retrieve current user data. Please verify the user ID and database status.");
}
const result = db.updateDocument(palettegramDB, usersCollection, currentUser.documents[0].$id, {
isVerified: true,
});
if (!result) {
throw new Error("Failed to update user verification status. Please check the database operation.");
}

Comment on lines 185 to 193

// const getOldUserDetails = await db.listDocuments(palettegramDB, usersCollection, [
// Query.equal("email", userEmail),
// ]);

// if (!getOldUserDetails) {
// throw new Error("user does not exist");
// }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing or implementing the commented-out code to maintain code cleanliness.

Consider implementing the commented-out functionality or removing it if it's not planned for future use.

userData.USER_ID === "" ||
userData.SECRET === " "
) {
if (password === "" || confirmpassword === "" || USER_ID === "" || SECRET === " ") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhance the validation check to include all fields comprehensively.

- if (password === "" || confirmpassword === "" || USER_ID === "" || SECRET === " ") {
+ if (!password.trim() || !confirmpassword.trim() || !USER_ID.trim() || !SECRET.trim()) {

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.

Suggested change
if (password === "" || confirmpassword === "" || USER_ID === "" || SECRET === " ") {
if (!password.trim() || !confirmpassword.trim() || !USER_ID.trim() || !SECRET.trim()) {

@github-actions github-actions bot added wait for reviewers SWOC S4 Social Winter of Code (S4) 2024 contribution tag labels Apr 24, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Out of diff range and nitpick comments (1)
src/components/pages/auth/verification/index.tsx (1)

50-50: Consider adding dependency array comments in useEffect for clarity.

Adding comments explaining why secret and accountId are included in the dependency array of useEffect can improve code maintainability by making the intentions behind these dependencies clear.

@@ -41,6 +41,10 @@ const getUserFieldByAccountId = async (userId: string) => {

const saveImage = async (image: File) => {
try {
if (!image) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling in saveImage.

- throw new Error("error aa rha hai");
+ throw new Error("Image upload failed due to an unspecified error. Please check the input and storage permissions.");

The error message should be more descriptive and professional to aid in debugging and user communication.


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.

Suggested change
if (!image) {
if (!image) {
throw new Error("Image upload failed due to an unspecified error. Please check the input and storage permissions.");

if (resp) {
return resp;
if (!result02) {
throw new Error("Error aa rha hai bannerURL mai");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve error message consistency.

- throw new Error("Error aa rha hai bannerURL mai");
+ throw new Error("Failed to update the banner URL in the database. Please check the document ID and database status.");

The error message should be consistent and informative, providing clear information about what went wrong and where.


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.

Suggested change
throw new Error("Error aa rha hai bannerURL mai");
throw new Error("Failed to update the banner URL in the database. Please check the document ID and database status.");


const handleFileUpload = async (event: any) => {
const fsize = Math.round(event.target.files[0].size / imageSizeLimit);
const fsize: number = Math.round(event.target.files[0].size / imageSizeLimit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate image size more effectively.

- toastify("Image size cannot be more that 1MB", "error");
+ toastify("Image size cannot be more than 1MB", "error");

Correct the typo in the toast message to enhance the user experience and professionalism.


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.

Suggested change
const fsize: number = Math.round(event.target.files[0].size / imageSizeLimit);
const fsize: number = Math.round(event.target.files[0].size / imageSizeLimit);

const fileObject = await saveImage(image?.file!);
if (!fileObject) throw new Error("Failed to load image, retry!");
if (!fileObject) {
throw new Error("Failed to load image, retry!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve error handling for image upload failures.

- throw new Error("Failed to load image, retry!");
+ throw new Error("Failed to upload image. Please check the network connection and try again.");

Provide a more detailed error message that guides the user on how to resolve the issue.


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.

Suggested change
throw new Error("Failed to load image, retry!");
throw new Error("Failed to upload image. Please check the network connection and try again.");

Comment on lines +41 to +49
const authResp = await account.updatePrefs({
username: username,
});

const dbData = await saveDataToDatabase(authResp);

if (!dbData) {
throw new Error("User data can't be saved properly");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve error handling in register.

- throw new Error("User data can't be saved properly");
+ throw new Error("Failed to save user data to the database. Please check the database connection and data integrity.");

Enhance the error message to provide more context and help in debugging.


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.

Suggested change
const authResp = await account.updatePrefs({
username: username,
});
const dbData = await saveDataToDatabase(authResp);
if (!dbData) {
throw new Error("User data can't be saved properly");
}
const authResp = await account.updatePrefs({
username: username,
});
const dbData = await saveDataToDatabase(authResp);
if (!dbData) {
throw new Error("Failed to save user data to the database. Please check the database connection and data integrity.");
}

});

if (!result) {
throw new Error("Error in verifying user");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve error handling in user verification.

- throw new Error("Error in verifying user");
+ throw new Error("Failed to update user verification status. Please check the database operation.");

The error message should be more informative and specific to aid in troubleshooting.


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.

Suggested change
throw new Error("Error in verifying user");
throw new Error("Failed to update user verification status. Please check the database operation.");

@@ -331,17 +331,17 @@ export default function SinglePost({
<div className="flex justify-around">
<article
onClick={() => onLikeClick(singlePost)}
className="flex flex-row gap-3 items-center transition ease-in-out duration-200 hover:cursor-pointer"
className="flex flex-row gap-3 items-center transition ease-in-out duration-200 hover:cursor-pointer hover:text-primary dark:hover:text-primary text-secondary-light dark:text-white"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure consistent UI/UX in post interactions.

- className="flex flex-row gap-3 items-center transition ease-in-out duration-200 hover:cursor-pointer hover:text-primary dark:hover:text-primary text-secondary-light dark:text-white"
+ className="flex flex-row gap-3 items-center transition ease-in-out duration-200 cursor-pointer hover:text-primary dark:hover:text-primary text-secondary-light dark:text-white"

Add cursor:pointer to the default class list to ensure that the cursor indicates a clickable item consistently across all states.


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.

Suggested change
className="flex flex-row gap-3 items-center transition ease-in-out duration-200 hover:cursor-pointer hover:text-primary dark:hover:text-primary text-secondary-light dark:text-white"
className="flex flex-row gap-3 items-center transition ease-in-out duration-200 cursor-pointer hover:text-primary dark:hover:text-primary text-secondary-light dark:text-white"

@Sanchitbajaj02 Sanchitbajaj02 removed the SWOC S4 Social Winter of Code (S4) 2024 contribution tag label May 2, 2024
@Sanchitbajaj02 Sanchitbajaj02 merged commit 6415993 into master May 2, 2024
6 checks passed
@Sanchitbajaj02 Sanchitbajaj02 deleted the issue-267 branch May 2, 2024 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working ⭐ enhancement Feature enhancement 🛠 goal: fix The label is related to fixing a bug MEDIUM Difficulty Level: Medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Workflow change of user creation
1 participant