-
Notifications
You must be signed in to change notification settings - Fork 9k
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: relative URL is being used where an absolute URL is required #20314
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
} | ||
|
||
await prisma.booking.update({ | ||
where: { id: booking.id }, | ||
data: { oneTimePassword: null }, | ||
}); | ||
|
||
return NextResponse.redirect(`/booking/${booking.uid}`); | ||
return NextResponse.redirect(`${url.origin}/booking/${booking.uid}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A relative URL (/booking/nhyUM5U2KVsyuxxxxxxxxx) is being used where an absolute URL is required in redirect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is the case, we better construct a full url in middleware so we prevent bugs for all other cases of redirect usages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, isn't this no-relative-url rule specific to middleware function only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anikdhabal This is not a middleware. It's an API route. Can we confirm this is a valid fix with evidence?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is not middleware. Sorry for the wrong title. But there's still an error here because NextResponse.redirect() requires an absolute URL, and we passed a relative URL.
Currently, due to this, we are getting this error: -Error:%20URL%20is%20malformed%20"/booking/cZP4p2eYbdd7Pptm3v1Y8N".%20Please%20use%20only%20absolute%20URLs%20-%20https://nextjs.org/docs/messages/middleware-relative-urls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zomars I've tested it, and it's working fine. As we can see in this file, we already perform the correct redirection, but these places were missing it.
For eg:-
`${url.origin}/booking/${bookingUid}?error=${encodeURIComponent("Error confirming booking")}` |
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (03/22/25)1 reviewer was added to this PR based on Keith Williams's automation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left a comment
No description provided.