In Nextjs how do you set serachParams in middleware ?

currently in my middleware im trying to add a user agent viewport serachParam to requests as seen in the nextjs docs here : https://nextjs.org/docs/app/api-reference/functions/userAgent , however supabase my auth provider also has middleware to validate cookies seen here : https://www.youtube.com/watch?v=v6UvgfSIjQ0, is it possible to merge these two and have a response return with my serachParams
Functions: userAgent | Next.js
The userAgent helper extends the Web Request API with additional properties and methods to interact with the user agent object from the request.
Supabase
YouTube
The Right Way to do Auth with the Next.js App Router - UPDATED
Authentication is essential for modern app development! In this video, Jon Meyers configures Supabase Auth to use cookies, and implements OAuth using GitHub in an Email Client, written with the Next.js App Router. https://supabase.com/docs/guides/auth/social-login/auth-github The Next.js App Router blurs the lines between Client and Server, th...
No description
12 Replies
! AlexNotTheLion
bump
FleetAdmiralJakob 🗕 🗗 🗙
just add a new search param do url.searchParams.set("dialog", "users") and url.searchParams.set('viewport', viewport) there is no problem in having both searchParams
! AlexNotTheLion
thats fine, the issue im currently seeing is the params im setting are not appearing in the url if the user is authenticated
FleetAdmiralJakob 🗕 🗗 🗙
even with my solution?
! AlexNotTheLion
yup, this is my current middlewhere where i set the viewport, the redirect ot the home page and dialog gets added if the user is not authenticated (i see both of those params in the url in that scenario) however, if the user is authenticated and theyre going to say the profile page there is no viewport query in the url
No description
! AlexNotTheLion
sorry forgot to press reply ^
FleetAdmiralJakob 🗕 🗗 🗙
could you console.log the response from supabase and the request I have the feeling that supabase does not care about the search params and deletes them
! AlexNotTheLion
sorry for the long reply, window 10 terminal is being a pain and putting things in objects, heres the output
request : "http://localhost:3000/?viewport=desktop"
response : ""
request : "http://localhost:3000/?viewport=desktop"
response : ""
! AlexNotTheLion
code
No description
! AlexNotTheLion
but i have also checked getting the params in a server component and they do get removed if i add the params manuall like localhost:3000/events?test=abc , the params stay the first thing the createClient method does it create an unmodified response like so, so i expect that takes out all the params ?
export const createClient = (request: NextRequest) => {
// Create an unmodified response
let response = NextResponse.next({
request: {
headers: request.headers,
},
});
export const createClient = (request: NextRequest) => {
// Create an unmodified response
let response = NextResponse.next({
request: {
headers: request.headers,
},
});
FleetAdmiralJakob 🗕 🗗 🗙
As I dont now these APIs well enough you could console log to check if the response in this example is with or without the search params
! AlexNotTheLion
Yup same response as above, doesn't have the search params as far as I can tell