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

136
Views
Local storage is empty

I created an SPA that uses oauth, it seams to work but there is an issue if I open the app for the first time.

Then local storage seams to be cleared.

My application, is written in vue but it seams to me that this is not a vue issue.

This is my code that does the redirect.

    let nonce = '';
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    for (let i = 0; i < 32; i++) {
        nonce += characters.charAt(Math.floor(Math.random() * characters.length));
    }
    document.cookie = nonce;
    localStorage.setItem('nonce', nonce);
    windows.location.href = 'my-oauth-url...';

This is my code that validates the nonce after the redirect:

    if (to.path.includes('/callback')) {
        const urlSearch = new URLSearchParams(to.hash);
        const nonce = extractResponseNonce(urlSearch);
        alert('stored nonce ' + localStorage.getItem('nonce'));
        alert('cookie ' + document.cookie)
        console.log('stored nonce ' + localStorage.getItem('nonce'))
        console.log('state ' + store.state.nonce)
        console.log('extracted nonce ' + nonce)
        // using document.cookie works
        if (localStorage.getItem('nonce') != nonce) {
            next('/error/nonceError')
            return
        }
}

If I use the localstoreage to compare the nonce I get null, and go to the nonce error page.

If I redo the login process again after that everthing works.

I checked with the alerts that the value is realy set before doing the first redirect.

PS: I always use the private mode of firefox for testing this application (I don't think that this should matter).

Do you have an idea why localstorage returns null to me but the cookie is filled correctly?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem was the transition between http and https.

I just called http in my browser, and because it was a test setup I did not do a redirect to https.
But the redirect-URL back to my frontend uses https, then the local-storage was empty because the url changed.
The cookie on the other hand doesn't mind about http or https it's just pinned at the domain.

about 4 years ago · Juan Pablo Isaza 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!