I am working with some old nest.js codebase and we have /login endpoint.
This endpoint is waiting for query param redirect_url.
redirect_url can contain multiple query params too like this http://localhost:3000/api/schemas/generate?appId=application&event=eventName®istry=registry.
And finally, we have something like this:
http://localhost:3000/api/login?redirect_url=http://localhost:3000/api/schemas/generate?appId=application&event=eventName®istry=registry
because it is not encoded expected that @Query() object is:
{
"redirect_url": "http://localhost:3000/api/schemas/generate?appId=application",
"event": "eventName",
"registry": "registry"
}
What is the best way to achieve this in nest.js and not lost query params?
{
"redirect_url": "http://localhost:3000/api/schemas/generate?appId=application&event=eventName®istry=registry"
}
If you want to send the redirect_url with query params first you have to encode it using encodeURIComponent and decode it in nest with decodeURIComponent. Do something like this:
const redirect_url = "http://localhost:3000/api/schemas/generate?appId=application";
const encoded_url = encodeURIComponent(redirect_url);
const url = `http://localhost:3000/api/login?redirect_url=${redirect_url}&event=eventName®istry=registry`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With