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: use NextResponse redirect #173

Merged
merged 1 commit into from
May 28, 2024

Conversation

peterphanouvong
Copy link
Collaborator

Explain your changes

  • use next response redirect instead of redirect from next/navigation
    Suppose there is a related issue with enough detail for a reviewer to understand your changes fully. In that case, you can omit an explanation and instead include either “Fixes #XX” or “Updates #XX” where “XX” is the issue number.

Checklist

🛟 If you need help, consider asking for advice over in the Kinde community.

Copy link
Contributor

coderabbitai bot commented May 28, 2024

Walkthrough

The changes primarily involve modifying several handler functions (callback, createOrg, login, logout, register) to return the result of routerClient.redirect(url) instead of directly calling the redirect method. Additionally, the redirect function in AppRouterClient has been updated to use NextResponse.redirect from next/navigation.

Changes

Files Change Summary
src/handlers/callback.js Modified callback function to return routerClient.redirect(postLoginRedirectURL).
src/handlers/createOrg.js Added return statement before routerClient.redirect(authUrl.toString()) in createOrg.
src/handlers/login.js Modified login function to return routerClient.redirect(authUrl.toString()).
src/handlers/logout.js Modified logout function to return routerClient.redirect(authUrl.toString()).
src/handlers/register.js Added return statement before routerClient.redirect(authUrl.toString()) in register.
src/routerClients/AppRouterClient.js Updated redirect function to use NextResponse.redirect from next/navigation.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the 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 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.

@peterphanouvong peterphanouvong merged commit 2cd4eaf into main May 28, 2024
2 checks passed
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: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 0ce1328 and ffb0212.
Files selected for processing (6)
  • src/handlers/callback.js (1 hunks)
  • src/handlers/createOrg.js (1 hunks)
  • src/handlers/login.js (1 hunks)
  • src/handlers/logout.js (1 hunks)
  • src/handlers/register.js (1 hunks)
  • src/routerClients/AppRouterClient.js (2 hunks)
Additional comments not posted (5)
src/handlers/createOrg.js (1)

19-19: Ensure all calls to createOrg properly handle the returned promise, as the function now returns a promise due to the return statement.

Verification successful

The createOrg function is used within a routeMap object in src/handlers/auth.js. This suggests that createOrg is likely invoked as part of a routing mechanism, which should handle the returned promise correctly.

However, to ensure that the promise returned by createOrg is properly handled, it would be prudent to verify how the routeMap object is utilized within the codebase. This will confirm whether the promise is awaited or handled appropriately.


The routeMap object is used in src/handlers/auth.js to return a function based on the endpoint. To ensure that the promise returned by createOrg is properly handled, we need to verify how the returned function from routeMap is invoked.

Let's extract the relevant lines around the usage of routeMap in src/handlers/auth.js to understand how the returned function is called.


The getRoute function returns a function from the routeMap based on the endpoint. To ensure that the promise returned by createOrg is properly handled, we need to verify how getRoute is used and how the returned function is invoked.

Let's search for the usage of getRoute in the codebase to understand how the returned function is called and whether the promise is handled correctly.


The getRoute function is used twice in src/handlers/auth.js. To ensure that the promise returned by createOrg is properly handled, we need to verify how the route variable, which holds the function returned by getRoute, is invoked.

Let's extract the relevant lines around the usage of getRoute in src/handlers/auth.js to understand how the route variable is used.


The route variable, which holds the function returned by getRoute, is invoked with await in both instances found in src/handlers/auth.js. This ensures that the promise returned by createOrg is properly handled.

  • appRouterHandler function:

    return route
      ? // @ts-ignore
        await route(new AppRouterClient(req, res))
      : new Response('This page could not be found.', {status: 404});
  • Another function (not named in the snippet):

    return route
      ? // @ts-ignore
        await route(new PagesRouterClient(req, res, clientOptions))
      : res.status(404).end();

Both instances correctly handle the promise returned by createOrg using await.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `createOrg` handle the returned promise.

# Test: Search for the function usage. Expect: Proper handling of the returned promise.
rg --type javascript $'createOrg'

Length of output: 67



Script:

#!/bin/bash
# Description: Verify all function calls to `createOrg` handle the returned promise.

# Test: Search for the function usage. Expect: Proper handling of the returned promise.
rg 'createOrg' --glob '*.js'

Length of output: 297



Script:

#!/bin/bash
# Description: Verify how `createOrg` is used in `src/handlers/auth.js`.

# Extract lines around the usage of `createOrg` in `src/handlers/auth.js`.
rg -A 5 -B 5 'createOrg' src/handlers/auth.js

Length of output: 514



Script:

#!/bin/bash
# Description: Verify how `routeMap` is used in the codebase to ensure proper handling of the promise returned by `createOrg`.

# Search for the usage of `routeMap` in the codebase.
rg 'routeMap' --glob '*.js'

Length of output: 117



Script:

#!/bin/bash
# Description: Verify how the function returned from `routeMap` is invoked in `src/handlers/auth.js`.

# Extract lines around the usage of `routeMap` in `src/handlers/auth.js`.
rg -A 5 -B 5 'routeMap\[endpoint\]' src/handlers/auth.js

Length of output: 265



Script:

#!/bin/bash
# Description: Verify how `getRoute` is used in the codebase to ensure proper handling of the promise returned by `createOrg`.

# Search for the usage of `getRoute` in the codebase.
rg 'getRoute' --glob '*.js'

Length of output: 195



Script:

#!/bin/bash
# Description: Verify how the `route` variable, which holds the function returned by `getRoute`, is invoked in `src/handlers/auth.js`.

# Extract lines around the usage of `getRoute` in `src/handlers/auth.js`.
rg -A 5 -B 5 'getRoute\(endpoint\)' src/handlers/auth.js

Length of output: 739

src/handlers/login.js (1)

26-26: Ensure all calls to login properly handle the returned promise, as the function now returns a promise due to the return statement.

Verification successful

No external calls to the login function were found in the codebase, indicating that there are no other places where the returned promise needs to be handled.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `login` handle the returned promise.

# Test: Search for the function usage. Expect: Proper handling of the returned promise.
rg --type javascript $'login'

Length of output: 63



Script:

#!/bin/bash
# Description: Verify all function calls to `login` handle the returned promise.

# Test: Search for the function usage. Expect: Proper handling of the returned promise.
rg 'login('

Length of output: 76



Script:

#!/bin/bash
# Description: Verify all function calls to `login` handle the returned promise.

# Test: Search for the function usage. Expect: Proper handling of the returned promise.
rg 'login\('

Length of output: 92

src/handlers/register.js (1)

26-26: Ensure all calls to register properly handle the returned promise, as the function now returns a promise due to the return statement.

Verification successful

The register function's returned promise is properly handled in both appRouterHandler and pagesRouterHandler functions. The promise is awaited, ensuring that the asynchronous operation completes before proceeding.

  • appRouterHandler:

    return route
      ? // @ts-ignore
        await route(new AppRouterClient(req, res))
      : new Response('This page could not be found.', {status: 404});
  • pagesRouterHandler:

    return route
      ? // @ts-ignore
        await route(new PagesRouterClient(req, res, clientOptions))
      : res.status(404).end();

These handlers correctly await the promise returned by the register function, ensuring proper handling of the asynchronous operation.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `register` handle the returned promise.

# Test: Search for the function usage. Expect: Proper handling of the returned promise.
rg --type javascript $'register'

Length of output: 66



Script:

#!/bin/bash
# Description: Verify all function calls to `register` handle the returned promise.

# Test: Search for the function usage. Expect: Proper handling of the returned promise.
rg --type js $'register'

Length of output: 454



Script:

#!/bin/bash
# Description: Extract relevant code from `src/handlers/auth.js` to verify handling of `register` function's returned promise.

# Extract lines around the usage of `register` function.
rg --type js -A 5 -B 5 $'register' src/handlers/auth.js

Length of output: 691



Script:

#!/bin/bash
# Description: Search for the usage of `routeMap` in the codebase to verify handling of the returned promise from `register`.

# Search for `routeMap` usage in JavaScript files.
rg --type js $'routeMap'

Length of output: 113



Script:

#!/bin/bash
# Description: Extract relevant code from `src/handlers/auth.js` to verify handling of the function returned by `routeMap`.

# Extract lines around the usage of `routeMap` to verify function invocation.
rg --type js -A 5 -B 5 $'routeMap' src/handlers/auth.js

Length of output: 487



Script:

#!/bin/bash
# Description: Search for the usage of `getRoute` in the codebase to verify handling of the returned function's promise.

# Search for `getRoute` usage in JavaScript files.
rg --type js $'getRoute'

Length of output: 191



Script:

#!/bin/bash
# Description: Extract more lines around the usage of `getRoute` in `src/handlers/auth.js` to verify handling of the returned function's promise.

# Extract lines around the usage of `getRoute` to verify function invocation.
rg --type js -A 10 -B 10 $'getRoute' src/handlers/auth.js

Length of output: 1431

src/handlers/logout.js (1)

26-26: Ensure all calls to logout properly handle the returned promise, as the function now returns a promise due to the return statement.

src/handlers/callback.js (1)

26-26: Ensure all calls to callback properly handle the returned promise, as the function now returns a promise due to the return statement.

@@ -31,7 +30,7 @@ export default class AppRouterClient extends RouterClient {
* @returns
*/
redirect(url) {
return redirect(url);
return NextResponse.redirect(url);
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The search results indicate that the routerClient.redirect method is called in several files, but there is no evidence that the returned NextResponse object is being handled properly. Each call to routerClient.redirect simply returns the result without any further handling.

To ensure proper handling, the returned NextResponse object should be used appropriately, such as by chaining .then() for promises or handling it in some other way.

Here are the specific lines that need attention:

  • src/handlers/register.js: return routerClient.redirect(authUrl.toString());
  • src/handlers/logout.js: return routerClient.redirect(authUrl.toString());
  • src/handlers/callback.js: return routerClient.redirect(postLoginRedirectURL);
  • src/handlers/login.js: return routerClient.redirect(authUrl.toString());
  • src/handlers/createOrg.js: return routerClient.redirect(authUrl.toString());

These lines should be reviewed and updated to ensure that the NextResponse object is handled correctly.

Analysis chain

Ensure all calls to redirect in AppRouterClient properly handle the returned promise, as the method now returns a NextResponse object.


The search results show multiple instances of the redirect method being called across various files. To ensure that all calls to the redirect method in AppRouterClient handle the returned NextResponse object properly, we need to specifically check the relevant lines in those files.

Here are the key locations to verify:

  • src/handlers/register.js
  • src/handlers/logout.js
  • src/handlers/callback.js
  • src/handlers/login.js
  • src/handlers/createOrg.js

These files contain calls to routerClient.redirect, which likely refers to the redirect method in AppRouterClient.

To proceed, we should inspect these files to ensure that the returned NextResponse object is handled correctly.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all method calls to `redirect` in `AppRouterClient` handle the returned `NextResponse` object.

# Test: Search for the method usage. Expect: Proper handling of the returned `NextResponse` object.
rg --type javascript $'redirect'

Length of output: 66



Script:

#!/bin/bash
# Description: Verify all method calls to `redirect` in `AppRouterClient` handle the returned `NextResponse` object.

# Test: Search for the method usage. Expect: Proper handling of the returned `NextResponse` object.
rg --type js $'redirect'

Length of output: 3000



Script:

#!/bin/bash
# Description: Verify that all calls to `routerClient.redirect` handle the returned `NextResponse` object properly.

# Check the relevant files for proper handling of the returned `NextResponse` object.
for file in src/handlers/register.js src/handlers/logout.js src/handlers/callback.js src/handlers/login.js src/handlers/createOrg.js; do
  echo "Checking $file"
  rg 'routerClient\.redirect' $file -A 3
done

Length of output: 1626

@AntoLepejian AntoLepejian mentioned this pull request May 28, 2024
4 tasks
peterphanouvong added a commit that referenced this pull request Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant