Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

320
Views
How to store token on server side [Angular Universal]

I found this post: https://github.com/angular/universal/issues/272 where user @gdi2290 explain how to add that functionalty

But I get error in my code:

/home/master/Documents/rs-dash/dist/server/server.bundle.js:317 throw new Error("Module build failed: Error: /home/master/Documents/rs-dash/src/app/app.node.module.ts (97,48): Property 'injector' does not exist on type 'ApplicationRef'.)\n/home/master/Documents/rs-dash/src/app/app.node.module.ts (97,61): Cannot find name 'YourServiceWithState'.)\n at _checkDiagnostics (/home/master/Documents/universal-cli/packages/@ngtools/webpack/src/loader.ts:115:15)\n at /home/master/Documents/universal-cli/packages/@ngtools/webpack/src/loader.ts:140:17"); ^

I added in node module:

constructor(public appRef: ApplicationRef) {

    }
    // lives in your node main module
    universalDoDehydrate(universalCache) {
        var yourServiceWithState = this.appRef.injector.get(YourServiceWithState)
        var key = 'yourServiceWithState._state'
        universalCache[key] = yourServiceWithState._state.justOneProp
    }

and in browser module:

constructor(public appRef: ApplicationRef) {
        // lives in your browser main module
        var key = 'yourServiceWithState._state'
        if (UNIVERSAL_CACHE[key]) {
            localStorage[key] = UNIVERSAL_CACHE[key]
        }
    }

Anyone know what is problem, I am using universal-cli?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I had the issue and developed a cache & server-side solution for it (4 separate packages for cache operations both on server and browser platforms).

Check the implementation at ng-seed/universal. Everything is handled via the @Cached(...) decorator on the method/loader/etc which you want it to be cached. Also, there's the possibility to use caching methods (has, get, set) using the caching API.

Here are the packages you need to use, for server-side caching:

  • @ngx-cache/core: cache utility
  • @ngx-cache/platform-browser: SPA/Browser platform implementation
  • @ngx-cache/platform-server: server platform implementation
  • @ngx-cache/fs-storage: storage utility (required for server platform)
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!