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

fix: Login Error #390

Merged
merged 3 commits into from
Jun 28, 2024
Merged

Conversation

vinayak-vohra
Copy link
Contributor

@vinayak-vohra vinayak-vohra commented Jun 20, 2024

Related Issue

fixes: #353

Description

  • Changed deleteSessions() to deleteSession("current") to delete only active user session, if any, before login.
  • Enclosed deleteSession() in a separate try-catch block to bypass generate_unauthorized_scope error, which means no active sessions were found (and hence can be ignored).
  • Set login cookies expire time to be same as appwrite session expire time, which can be set in the appwrite console under auth>security

Screenshots

Flow 1: Normal Login

Palettegram.-.Login.mp4

Flow 2: Session active in Appwrite, but not on browser (accidental cookie clear by user)

User.Dashboard._.Palettegram.mp4

Flow 3: Logged in user

Palettegram.mp4

Summary by CodeRabbit

  • New Features

    • Enhanced login functionality to include session expiration time, improving user experience with better session management.
  • Bug Fixes

    • Improved error handling for unauthorized scope errors during login attempts.
  • Improvements

    • Cookies now include expiration parameters, providing more accurate session control and security.

Copy link

vercel bot commented Jun 20, 2024

@vinayak-vohra is attempting to deploy a commit to the Sanchit Bajaj's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jun 20, 2024

Walkthrough

The recent updates involve changes to the login function in auth.api.ts to enhance session handling and error management, and modifications to the LoginComponent in index.tsx to manage session expiration and cookies more effectively. These adjustments aim to solve issues with re-login after email verification and ensure smoother user authentication.

Changes

File Path Change Summary
src/backend/auth.api.ts Improved session deletion, added error handling for unauthorized scope errors, and included session expiration time retrieval in the login function.
src/components/pages/auth/login/index.tsx Updated LoginComponent to handle the new login function return structure and updated setCookie calls to include session expiration parameters.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LoginComponent
    participant AuthAPI

    User->>LoginComponent: Enters email and password
    LoginComponent->>AuthAPI: Calls login(email, password)
    AuthAPI->>AuthAPI: Handle session deletion, error handling
    AuthAPI->>LoginComponent: Return { user, expires }
    LoginComponent->>LoginComponent: Sets cookies with expiration
    LoginComponent->>User: Returns login response
Loading

Assessment against linked issues

Objective (Issue #353) Addressed Explanation
Fix the inability to re-login after email verification.
Update the session and cookie management in the login flow

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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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 gssoc GSSOC'24 Required Label title needs formatting Title of issue or pull request does not match the guidelines labels Jun 20, 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, @vinayak-vohra! 🎉 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'

@vinayak-vohra vinayak-vohra changed the title Fix #353 Fix: Login Error Jun 20, 2024
@vinayak-vohra vinayak-vohra changed the title Fix: Login Error fix: Login Error Jun 20, 2024
@github-actions github-actions bot removed the title needs formatting Title of issue or pull request does not match the guidelines label Jun 20, 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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3ea8150 and 493fe8b.

Files selected for processing (2)
  • src/backend/auth.api.ts (1 hunks)
  • src/components/pages/auth/login/index.tsx (2 hunks)
Additional context used
Biome
src/backend/auth.api.ts

[error] 120-120: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

src/components/pages/auth/login/index.tsx

[error] 194-200: Provide an explicit type prop for the button element. (lint/a11y/useButtonType)

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset


[error] 269-275: Provide an explicit type prop for the button element. (lint/a11y/useButtonType)

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset


[error] 280-286: Provide an explicit type prop for the button element. (lint/a11y/useButtonType)

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

Additional comments not posted (2)
src/backend/auth.api.ts (1)

146-159: Ensure proper error handling and session management in the updated login function.

The changes made to handle session-specific errors and manage session expiration are aligned with best practices for robust authentication systems. However, consider adding more specific logging for different types of errors to aid in debugging and maintenance.

src/components/pages/auth/login/index.tsx (1)

Line range hint 67-83: Update LoginComponent to handle new response structure from the login function.

The modifications in LoginComponent to accommodate the expires field in the cookie settings align with security best practices by synchronizing session expiration on both the server and client sides. This should help prevent session hijacking and other common security issues.

@vinayak-vohra
Copy link
Contributor Author

@Sanchitbajaj02 please verify.

const user = await getUserByAccountId(accountId);
return user;
return { user, expires: new Date(expire) };
Copy link
Owner

Choose a reason for hiding this comment

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

this will expire immediately, you need to add some buffer time. I prefer to add 2 days

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to know why would this expire immediately?

As per the Appwrite docs, the session object contains an expire property which is a date string. This string is converted to a date object here because it is required as such by nookies.

Also, the cookie expire time is set to be in sync with the appwrite session validation (1 year by default), that can be changed.

Cookie expire time (matches appwrite session length):
image

Appwrite console to set session length (auth > security):
image
Changing this to 2 days would set the cookie expire time to 2 days for users.

Copy link
Owner

Choose a reason for hiding this comment

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

Let me test that out locally, and then finalize the PR

@Sanchitbajaj02 Sanchitbajaj02 added 🪲 bug Something isn't working 🛠 goal: fix The label is related to fixing a bug MEDIUM Difficulty Level: Medium level2 25 points and removed wait for reviewers labels Jun 23, 2024
@Sanchitbajaj02 Sanchitbajaj02 merged commit 9c076c2 into Sanchitbajaj02:master Jun 28, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working 🛠 goal: fix The label is related to fixing a bug gssoc GSSOC'24 Required Label level2 25 points MEDIUM Difficulty Level: Medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Unable to re-login after email verification
2 participants