Skip to content

bug: handleSignIn used wrong URL for callback url check #968

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

Open
leric opened this issue May 22, 2025 · 1 comment
Open

bug: handleSignIn used wrong URL for callback url check #968

leric opened this issue May 22, 2025 · 1 comment
Assignees
Labels
bug Something isn't working pending-verification

Comments

@leric
Copy link

leric commented May 22, 2025

Describe the bug

https://github.com/logto-io/js/blob/master/packages/next/server-actions/index.ts#L60

In this function handleSignIn, if the passed in param searchParamsOrUrl is not a instance of URL, it will construct a bad url for client.handleSignInCallbackto handle.

In the Next.js (App Router) tutorial, the sample code do pass a URLSearchParams as searchParamsOrUrl, so if your redirect url is not /callback, it will throw error callback_uri_verification.redirect_uri_mismatched

Expected behavior

Use the sample code given by Next.js (App Router) tutorial:

import { handleSignIn } from '@logto/next/server-actions';
import { redirect } from 'next/navigation';
import { NextRequest } from 'next/server';
import { logtoConfig } from '../logto';

export async function GET(request: NextRequest) {
  const searchParams = request.nextUrl.searchParams;
  await handleSignIn(logtoConfig, searchParams);

  redirect('/');
}

Should handle login callback correctly.

How to reproduce?

Set redirect URI to any url other than http://hostname/callback, e.g. http://localhost:3000/api/auth/callback
handleSignIn will check the actual redirect url agains http://hostname/callback, result in a 'callback_uri_verification.redirect_uri_mismatched' error

Environment

Logto Cloud

Screenshots

No response

@leric leric added the bug Something isn't working label May 22, 2025
@wangsijie
Copy link
Contributor

Thank you for raising this issue. If your redirect URL is not /callback, you should construct and pass your own URL instance. That is why we allow passing an URL object in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending-verification
Development

No branches or pull requests

2 participants