Can't send cookies with nest.js backend on azure web service (serverless)

Viewed 181

I have troubles gettting cookies to work in my production environment which uses a Nest.js API Backend on Azure WebServices (with functions). I basically followed this guide: https://dev.to/azure/build-your-first-serverless-app-with-angular-nestjs-and-azure-108h

I also added an angular frontend app, also hosted on Azure. But as far as my testing concerns this does not matter.

I want to add authorization by JWT stored in a cookie. However, the Backend does not add the cookie to the header in production. In development (localhost) everything works like a charm. It works with the local/dev frontend calling the local/dev backend as well as when I use the VSC Rest Client to just call the API.

However in production I won't receive the cookie nor other header I test. I configured CORS in Azure and this kind of looks good as I do get a HTTP200 and not a CORS Error back. Just the header info is missing.

I already read a lot of advice, but none helped. I do set 'width credentials' (also in azure). Do you experts have any advice what to try or what might be the problem?

Thanks

Controller for testing purposes ...

@Get("server-check")
  @HttpCode(HttpStatus.OK)
  @Header('Set-Cookie', 'cookieName = 12345; secure; SameSite=none"') // "Usin header decorator"
  @Header('Access-Control-Expose-Headers', 'set-cookie, authorization') // 
  async serverCheck(
    @Res() response: Response) {
    response.cookie('rememberme', '1') // Using express res object.
    return response.send('Cookie has been set! :)')
  }

Response from Production env (no cookie in application tab) Screen from Network-Response in Browser

Response from REST call in VSC

HTTP/1.1 200 OK
Connection: close
Date: Thu, 05 May 2022 11:51:27 GMT
Transfer-Encoding: chunked
Request-Context: appId=cid-v1:b8d7a5c0-962f-40ec-b128-b47139939cf4

Cookie has been set! :)
0 Answers
Related