After a user clicks the button to access my website through email authentication, I need to verify if they have tokens. When they are redirected from Gmail to my page, there is a search parameter in the form of verification_token=**
. If the user has already been authorized, this token needs to be removed.
According to the documentation on NextJS, I should use the NextResponse.rewrite
function in middleware.ts to delete the token. However, when using this function, the page still displays with the same search parameter. I am using app router and Next 14.
I have attempted to delete the search parameter using
url.searchParams.delete('verification_token');
within the rewrite function, but it has not resolved the issue as the parameter remains. I have also tried different approaches such as nextResponse.redirect
, but none have provided a solution.