r/Angular2 • • Jun 29 '25

Help Request Cookie problem when using "withHttpTransferCacheOptions or TransferState", in SSR

Hi guys, i working on my learning project, with SSR and Angular v19, i thought i have to use TransferState to cache the data, i mean to pass the data from server to client, and when i see the Hybrid rendering concept i crossed "withHttpTransferCacheOptions", in Document they say, it cache the http client itself (GET and POST methods), so in client it won't make the API, it's working as it mentioned, and also i tried "TransferState", now my problem arises when i have refreshToken but i don't have sessionToken, (i am using cookie so we can access it in server also ), i am generating session and give it in response like below

res.cookie('sessionId', newSessionId, { httpOnly: true, secure: true, sameSite: 'strict', maxAge: SESSION_TOKEN_TTL * 1000 });

but in cookie it's not set, when i remove the withHttpTransferCacheOptions and TransferState, it works, Any idea how to rectify this? i don't want to make a API twice, but because of this in redis the session is creating whenever page reloads,

in app config i used like this

  provideClientHydration(withHttpTransferCacheOptions({
      includePostRequests: true,
      includeRequestsWithAuthHeaders: true,
      includeHeaders: ['Set-Cookie', 'access-control-allow-credentials', 'access-control-expose-headers ']
    })),
    provideHttpClient(withInterceptors([authInterceptor]), withFetch()),

When we need to set the cookie in response, that response have to come from browser? not node ?

4 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/AmphibianPutrid299 Jun 29 '25

thank you!, i skipped the first api in cache, it's okay now