Worker for access token after the url

For Workes & Pages, what is the name of the domain?

What is the issue or error you’re encountering

I need to make a page /contact that will have parameters for example /contact?qr={token} where if the user doesn’t put in the right token it redirects back to root of the site, but I’m currently not able to get it to work like I need it to. With my current code anything I type after the “/contact?” will also give me the right page with no token required.

What steps have you taken to resolve the issue?

This is the code, yes I used AI as I’m only learning JS
addEventListener(‘fetch’, event => {
event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {

const url = new URL(request.url);

if (url.pathname === ‘/contact’ && url.searchParams.get(‘qr’) === ‘testtoken’) {
return fetch(request);
} else {
return Response.redirect(url.origin + ‘/’, 302);
}
}