Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda