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: successful login should not take you to the login page #4056

Merged
merged 4 commits into from
Aug 6, 2024

Conversation

coderwyd
Copy link
Contributor

@coderwyd coderwyd commented Aug 6, 2024

Description

After logging in, using the address bar /auth/login will not jump to the login page.
close: #4051

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features
    • Enhanced access control logic for core routes, allowing for streamlined navigation without unnecessary permission checks.
  • Bug Fixes
    • Improved handling of login routes when an access token is present, ensuring proper redirection and access.
  • Refactor
    • Simplified the control flow for access permissions, separating core route checks for better readability and maintainability.
  • Chores
    • Cleaned up package.json by removing unnecessary spaces in the scripts section for improved code cleanliness.

@coderwyd coderwyd requested review from anncwb, vince292007 and a team as code owners August 6, 2024 08:35
Copy link

changeset-bot bot commented Aug 6, 2024

⚠️ No Changeset found

Latest commit: 564ed47

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Aug 6, 2024

Walkthrough

The changes enhance the access control logic in the setupAccessGuard function across multiple applications. The modifications provide clearer conditions for bypassing token checks on core routes, improving the flow and readability of the guard logic. These updates ensure that users with valid tokens can access specific routes seamlessly, addressing navigation issues encountered after login.

Changes

Files Change Summary
apps/web-antd/src/router/guard.ts Improved access control for core routes; simplified logic for handling login paths with existing tokens.
apps/web-ele/src/router/guard.ts Restructured access checks for clarity; separated core route checks for improved flow and readability.
apps/web-naive/src/router/guard.ts Enhanced access control logic; streamlined handling of core routes and login path based on access tokens.
package.json Cosmetic change in the update:deps script to improve code cleanliness by removing unnecessary space.

Assessment against linked issues

Objective Addressed Explanation
Ensure users are redirected correctly after login (#[4051])
Improve access control logic for core routes (#[4051])

🐰 In the code, I've found my way,
Through routes of access, bright as day.
With tokens in hand, no login delay,
Hopping to home, come what may!
Clarity blooms, like flowers in May! 🌼


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

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.

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 0c18912 and 77b920b.

Files selected for processing (3)
  • apps/web-antd/src/router/guard.ts (1 hunks)
  • apps/web-ele/src/router/guard.ts (1 hunks)
  • apps/web-naive/src/router/guard.ts (1 hunks)
Additional comments not posted (6)
apps/web-antd/src/router/guard.ts (2)

65-71: Improve readability and maintainability.

The added logic for handling core routes that do not require permission checks is clear and improves the readability of the code. Separating the core route check into its own conditional block makes the control flow more organized.


67-68: Ensure correct redirection for login path.

The added logic correctly handles the case where the route is the login path and an access token is present, redirecting the user to the specified path or the homepage. This ensures that users are not redirected back to the login page after logging in.

apps/web-ele/src/router/guard.ts (2)

65-71: Improve readability and maintainability.

The added logic for handling core routes that do not require permission checks is clear and improves the readability of the code. Separating the core route check into its own conditional block makes the control flow more organized.


67-68: Ensure correct redirection for login path.

The added logic correctly handles the case where the route is the login path and an access token is present, redirecting the user to the specified path or the homepage. This ensures that users are not redirected back to the login page after logging in.

apps/web-naive/src/router/guard.ts (2)

65-71: Improve readability and maintainability.

The added logic for handling core routes that do not require permission checks is clear and improves the readability of the code. Separating the core route check into its own conditional block makes the control flow more organized.


67-68: Ensure correct redirection for login path.

The added logic correctly handles the case where the route is the login path and an access token is present, redirecting the user to the specified path or the homepage. This ensures that users are not redirected back to the login page after logging in.

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

Outside diff range, codebase verification and nitpick comments (3)
apps/web-antd/src/router/guard.ts (1)

3-3: Reorder import statements for better readability.

The import statement DEFAULT_HOME_PATH should come before LOGIN_PATH to follow the alphabetical order.

-import { LOGIN_PATH, DEFAULT_HOME_PATH } from '@vben/constants';
+import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants';
Tools
GitHub Check: Lint (20, macos-latest)

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

GitHub Check: Lint (20, ubuntu-latest)

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

apps/web-ele/src/router/guard.ts (1)

3-3: Reorder import statements for better readability.

The import statement DEFAULT_HOME_PATH should come before LOGIN_PATH to follow the alphabetical order.

-import { LOGIN_PATH, DEFAULT_HOME_PATH } from '@vben/constants';
+import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants';
Tools
GitHub Check: Lint (20, macos-latest)

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

GitHub Check: Lint (20, ubuntu-latest)

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

apps/web-naive/src/router/guard.ts (1)

3-3: Reorder import statements for better readability.

The import statement DEFAULT_HOME_PATH should come before LOGIN_PATH to follow the alphabetical order.

-import { LOGIN_PATH, DEFAULT_HOME_PATH } from '@vben/constants';
+import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants';
Tools
GitHub Check: Lint (20, macos-latest)

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

GitHub Check: Lint (20, ubuntu-latest)

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 77b920b and 9612892.

Files selected for processing (3)
  • apps/web-antd/src/router/guard.ts (2 hunks)
  • apps/web-ele/src/router/guard.ts (2 hunks)
  • apps/web-naive/src/router/guard.ts (2 hunks)
Additional context used
GitHub Check: Lint (20, macos-latest)
apps/web-antd/src/router/guard.ts

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

apps/web-ele/src/router/guard.ts

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

apps/web-naive/src/router/guard.ts

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

GitHub Check: Lint (20, ubuntu-latest)
apps/web-antd/src/router/guard.ts

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

apps/web-ele/src/router/guard.ts

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

apps/web-naive/src/router/guard.ts

[failure] 3-3:
Expected "DEFAULT_HOME_PATH" to come before "LOGIN_PATH"

Additional comments not posted (3)
apps/web-antd/src/router/guard.ts (1)

65-73: LGTM! But verify the function usage in the codebase.

The code changes improve the clarity and efficiency of the access guard logic.

However, ensure that all function calls to setupAccessGuard match the new logic.

Verification successful

LGTM! The setupAccessGuard function implementation is consistent across all relevant files.

The code changes improve the clarity and efficiency of the access guard logic.

  • apps/web-naive/src/router/guard.ts
  • apps/web-antd/src/router/guard.ts
  • apps/web-ele/src/router/guard.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `setupAccessGuard` match the new logic.

# Test: Search for the function usage. Expect: Only occurrences of the new logic.
rg --type javascript -A 5 $'setupAccessGuard'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify all function calls to `setupAccessGuard` match the new logic.

# Test: Search for the function usage. Expect: Only occurrences of the new logic.
rg --type js -A 5 $'setupAccessGuard'

Length of output: 36


Script:

#!/bin/bash
# Description: Verify the existence and usage of the `setupAccessGuard` function across all file types.

# Search for the definition of `setupAccessGuard` function
rg 'function setupAccessGuard'

# Search for any potential usage of `setupAccessGuard` across all file types
rg 'setupAccessGuard'

Length of output: 708


Script:

#!/bin/bash
# Description: Compare the `setupAccessGuard` function implementation across three files to ensure consistency.

# Extract the `setupAccessGuard` function implementation from each file
rg --type ts -A 20 'function setupAccessGuard' apps/web-naive/src/router/guard.ts
rg --type ts -A 20 'function setupAccessGuard' apps/web-antd/src/router/guard.ts
rg --type ts -A 20 'function setupAccessGuard' apps/web-ele/src/router/guard.ts

Length of output: 2144

apps/web-ele/src/router/guard.ts (1)

65-73: LGTM! But verify the function usage in the codebase.

The code changes improve the clarity and efficiency of the access guard logic.

However, ensure that all function calls to setupAccessGuard match the new logic.

apps/web-naive/src/router/guard.ts (1)

65-73: LGTM! But verify the function usage in the codebase.

The code changes improve the clarity and efficiency of the access guard logic.

However, ensure that all function calls to setupAccessGuard match the new logic.

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 9612892 and 2039d68.

Files selected for processing (1)
  • package.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • package.json

@vince292007
Copy link
Collaborator

The ci didn't pass. You can check it.

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 2039d68 and 564ed47.

Files selected for processing (3)
  • apps/web-antd/src/router/guard.ts (2 hunks)
  • apps/web-ele/src/router/guard.ts (2 hunks)
  • apps/web-naive/src/router/guard.ts (2 hunks)
Additional comments not posted (6)
apps/web-antd/src/router/guard.ts (2)

3-3: Import DEFAULT_HOME_PATH is a good addition.

The addition of DEFAULT_HOME_PATH helps in providing a default redirect path for authenticated users.


65-73: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to setupAccessGuard and its logic are correctly implemented throughout the codebase.

Verification successful

The setupAccessGuard function is defined and used in three different files: apps/web-ele/src/router/guard.ts, apps/web-naive/src/router/guard.ts, and apps/web-antd/src/router/guard.ts. The logic within these functions appears to be consistent across the files. Each instance sets up a router guard that checks for basic routes and handles redirection if the user is already authenticated.

LGTM! The function setupAccessGuard and its logic are correctly implemented throughout the codebase.

  • apps/web-ele/src/router/guard.ts
  • apps/web-naive/src/router/guard.ts
  • apps/web-antd/src/router/guard.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `setupAccessGuard` and its logic.

# Test: Search for the function usage. Expect: Only occurrences of the new logic.
rg --type ts -A 10 $'setupAccessGuard'

Length of output: 3103

apps/web-ele/src/router/guard.ts (2)

3-3: Import DEFAULT_HOME_PATH is a good addition.

The addition of DEFAULT_HOME_PATH helps in providing a default redirect path for authenticated users.


65-73: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to setupAccessGuard and its logic are correctly implemented throughout the codebase.

Verification successful

Function usage of setupAccessGuard verified

The setupAccessGuard function is correctly defined and called within the files apps/web-ele/src/router/guard.ts, apps/web-antd/src/router/guard.ts, and apps/web-naive/src/router/guard.ts. The logic within the function is consistent across these instances.

  • apps/web-ele/src/router/guard.ts
  • apps/web-antd/src/router/guard.ts
  • apps/web-naive/src/router/guard.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `setupAccessGuard` and its logic.

# Test: Search for the function usage. Expect: Only occurrences of the new logic.
rg --type ts -A 10 $'setupAccessGuard'

Length of output: 3103

apps/web-naive/src/router/guard.ts (2)

3-3: Import DEFAULT_HOME_PATH is a good addition.

The addition of DEFAULT_HOME_PATH helps in providing a default redirect path for authenticated users.


65-73: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to setupAccessGuard and its logic are correctly implemented throughout the codebase.

Verification successful

Function usage verified

The function setupAccessGuard and its logic are correctly implemented and consistently used throughout the codebase in the following files:

  • apps/web-ele/src/router/guard.ts
  • apps/web-antd/src/router/guard.ts
  • apps/web-naive/src/router/guard.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `setupAccessGuard` and its logic.

# Test: Search for the function usage. Expect: Only occurrences of the new logic.
rg --type ts -A 10 $'setupAccessGuard'

Length of output: 3103

@coderwyd
Copy link
Contributor Author

coderwyd commented Aug 6, 2024

The ci didn't pass. You can check it.

It has been fixed.

@anncwb anncwb merged commit e27be2d into vbenjs:main Aug 6, 2024
15 checks passed
@coderwyd coderwyd deleted the fix/4051 branch August 7, 2024 01:04
@github-actions github-actions bot locked and limited conversation to collaborators Sep 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: 登录后通过地址栏/auth/login任然会跳转到登录页
4 participants