VigyBag icon indicating copy to clipboard operation
VigyBag copied to clipboard

Added authentication requirement for cart and wishlist functionality

Open LuckyNawale opened this issue 3 months ago • 3 comments

🔐 Authentication Enhancement

Changes Made:

✅ Users must login before adding items to cart ✅ Users must login before adding items to wishlist
✅ Enhanced AuthContext with proper user state management ✅ Added proper error messages and redirects to login page ✅ Fixed navigation paths to correct auth route

Testing:

  • [x] Cart functionality requires authentication
  • [x] Wishlist functionality requires authentication
  • [x] Proper error messages displayed
  • [x] Redirects to login page work correctly

Fixes the security issue where users could add items without authentication.

Summary by CodeRabbit

  • New Features

    • Requires sign-in for Buy Now, Add to Cart, and Wishlist actions. Unauthenticated users receive clear prompts and are redirected to the login page.
    • Improved session handling with persistent awareness of login status, user details, and a logout option for easier account management.
  • Documentation

    • Fixed a typo in the README regarding contribution guidelines.

LuckyNawale avatar Aug 27 '25 17:08 LuckyNawale

Someone is attempting to deploy a commit to the Vivek Prajapati's projects Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Aug 27 '25 17:08 vercel[bot]

Walkthrough

Adds authentication gating to product interactions. ProductGrid and ProductCard now check AuthContext.isLoggedIn before Buy Now, Add to Cart, and Wishlist actions, showing toasts/alerts and navigating to /auth if unauthenticated. AuthContext gains isLoggedIn, user data, and logout. README typo corrected.

Changes

Cohort / File(s) Summary
Documentation
README.md
Fixes a typo: “accpet” -> “accept”. No other content or structure changes.
Auth Context State
src/context/AuthContext.jsx
Adds isLoggedIn and user state; updates loginAsAdmin/loginAsUser to set isLoggedIn and user; adds logout; exposes isLoggedIn, user, logout via provider.
User Components — Auth Gating
src/User/components/Popular_Categories/ProductGrid.jsx, src/User/components/ProductCard/ProductCard.jsx
Introduces auth checks before Buy Now, Add to Cart, and Wishlist actions. If not logged in: show toast/alert and navigate to /auth. If logged in: proceed with existing actions and success toasts where applicable.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant UI as Product UI (Grid/Card)
  participant AC as AuthContext
  participant R as Router
  participant T as Toast/Alert
  participant S as Action Handler (Cart/Wishlist/Checkout)

  rect rgb(245,248,255)
    U->>UI: Click action (Buy/Add/Wishlist)
    UI->>AC: Check isLoggedIn
    alt Not logged in
      AC-->>UI: isLoggedIn = false
      UI->>T: Show "Please login..." message
      UI->>R: navigate('/auth')
    else Logged in
      AC-->>UI: isLoggedIn = true
      UI->>S: Perform action
      S-->>UI: Result
      UI->>T: Show success/failure
    end
  end
sequenceDiagram
  autonumber
  participant App as App
  participant AC as AuthContext
  participant Admin as Admin Login
  participant User as User Login

  Note over AC: Initial: isAdmin=false, isLoggedIn=false, user=null
  Admin->>AC: loginAsAdmin()
  AC-->>App: isAdmin=true, isLoggedIn=true, user=null
  User->>AC: loginAsUser(userData)
  AC-->>App: isAdmin=false, isLoggedIn=true, user=userData
  App->>AC: logout()
  AC-->>App: isAdmin=false, isLoggedIn=false, user=null

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I thump my paws at gates now set,
No sneaky hops to carts just yet—
Login first, then off we go,
To wishlist fields where carrots grow.
A tidy README, crisp and clean;
Auth in the burrow, safe and keen. 🥕🐇

[!TIP]

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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.
  • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

coderabbitai[bot] avatar Aug 27 '25 17:08 coderabbitai[bot]

Kindly mention your Issue number and at this time we don't want to authenticate user in these pages ... when they will be in their checkout page then there login will required only

codervivek5 avatar Aug 27 '25 18:08 codervivek5