Working on a school project: a website on which user can log with the school's Oauth, I am trying to use the Nestjs way to do a redirect from the backend API.
I think I follow quite simply the doc: https://docs.nestjs.com/controllers#redirection :
I store the redirection url in an env variable, so I can't simply do @Redirect(myUrl) since the env are accessed with a this pointer to the ConfigService (still tyring to do the Nestjs way)
Here a simplified version of the route's method:
import {
Query, Redirect, Session
} from '@nestjs/common'
@Get('/callback')
@Redirect()
async authCallback() {
const url = this.configService.get('AUTH_REDIRECT_URL');
console.log(url);
return {url};
}
From the console I can see the url has a value (from the env file).
back_end_server_1 | http://localhost:3001/MainPage
Yet, when the OAuth redirects to my /callback route and it returns, the redirect on client side looks like this:
HTTP/1.1 302 Found
X-Powered-By: Express
Location:
Vary: Accept
[...]
No location, so I end up with a page with containing Found. Redirecting to.
This project runs with two docker containers, one for the front and one for the back, but the issue arise when running with the containers or locally on the host (by npm run start:dev)
It works perfectly if I hardcode the url in the decorator parameter: @Redirect('http://...'
Any though on what I am doing wrong? Could it be a version issue? Or I am not understanding the right way to do redirect?
Best, Brian.
Turns out after, few hours of headache, it was exactly how to do it, but it seems like a serializer on the controller was interfering with the response content (I guess)
Now I've moved the serializer only on the route where its needed.