#LocalStroage and Api call issue in Angular v20

4 messages · Page 1 of 1 (latest)

vernal nimbus
#

I am calling an API in an Angular SSR project (Angular 20). When I refresh the page, it calls the same API twice, and I am unable to get the token in the first API call. The second call works perfectly. How can I solve this issue?

light wren
#

You cannot use localStorage with SSR. localStorage is a client only API. Node.JS does support it now, but that will store things locally on the server and it won't magically be available on the client.
The only storage that is available across client and server in an SSR environment is cookies.

daring frigate
#

Hi How are you doing ?
First api call happens on the server, on the other hand second api call happens in the browser where you can access the token.
This is the main issue. Think of using TransferState from angular core.

vernal nimbus
#

I dont think show TransferState will work with localstorage,