Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda