error refreshing page with local storage #1130

Closed
opened 2025-08-09 17:18:59 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @lucamorelli on 1/9/2017

Hi, In my app I have a service that prepare the request option adding jwt tokens to request calls this way

    public get jwt(): RequestOptions {
        var authHeader = new Headers();
        var token = localStorage.getItem('access_token');
        authHeader.append('Authorization', 'Bearer ' + token);
        authHeader.append('Content-Type', 'application/json');
        return new RequestOptions({ headers: authHeader });
    }

it works normally, but if during navigation I press F5 to and refresh, I obtain this error message

Exception: Call to Node module failed with error: ReferenceError: localStorage is not defined
at RequestOptionsService.Object.defineProperty.get [as jwt] (D:\Sorgenti\Interno\MyCrm\src\CrmApp\ClientApp\dist\main-server.js:20252:26)
at CampagnaService.aperteSimpleList (D:\Sorgenti\Interno\MyCrm\src\CrmApp\ClientApp\dist\main-server.js:20666:59)

Am I missing somthing?

*Originally created by @lucamorelli on 1/9/2017* Hi, In my app I have a service that prepare the request option adding jwt tokens to request calls this way ``` public get jwt(): RequestOptions { var authHeader = new Headers(); var token = localStorage.getItem('access_token'); authHeader.append('Authorization', 'Bearer ' + token); authHeader.append('Content-Type', 'application/json'); return new RequestOptions({ headers: authHeader }); } ``` it works normally, but if during navigation I press F5 to and refresh, I obtain this error message ``` Exception: Call to Node module failed with error: ReferenceError: localStorage is not defined at RequestOptionsService.Object.defineProperty.get [as jwt] (D:\Sorgenti\Interno\MyCrm\src\CrmApp\ClientApp\dist\main-server.js:20252:26) at CampagnaService.aperteSimpleList (D:\Sorgenti\Interno\MyCrm\src\CrmApp\ClientApp\dist\main-server.js:20666:59) ``` Am I missing somthing?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1130
No description provided.