I am currently working with an express server and using tsoa to define my endpoints.
One of the endpoints on my server is a login endpoint that returns an authentication token, which I then store in the browser of a web application:
@Route('auth')
@Tags('Auth')
export class AuthController extends Controller {
@SuccessResponse('200', 'Returns Token')
@Post('/login')
public async login(@Body() body: TokenRequest): Promise<TokenResponse> {
// ... login implementation.
return token
}
}
Now, I am developing a second application that will be hosted on a subdomain of the same domain as the first application. I want both applications to share the same authentication token. To achieve this, I need to set an authentication token (and refresh token) cookie. However, I am unable to find any documentation in tsoa or express on how to accomplish this.
Ideally, I would like my login function to look something like this:
@Post('/login')
public async login(@Body() body: TokenRequest, @Response() res: Response): Promise<TokenResponse> {
// ... login implementation.
res.setHeader(...) // or
cookie.set(...)
return token
}
The issue is that I cannot access the express response within the tsoa endpoint. I have also attempted to use the setHeader
method on the tsoa Controller class, but it does not work either.
Can anyone provide guidance on how to proceed? Am I approaching this problem from the wrong angle?