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

108
Visualizações
Need my localhost to save input data and not reset when redirected to the initial page

Problem: I need help fixing an issue with my js file and updating my code, so the program will not reset every time I return to the initial page.

Program: The functionality of the site works as follows: Running the program on the localhost will first prompt the user to input a username. This username is used as ID for the user chat/channel. Additionally, the user is able to create and join multilipe channels. If two hosts are running concurrently and have joined the same chat, then the users can send messages to each other and update instantly.

Here's the Repository: https://github.com/NilesDobbs/Assignment14

Goal: Right now, the functionality I'm aiming for is that once a user inputs their username and starts a chat in the room, if they were to return to /welcome manually, the program would save their name, and the page would not ask them to input their name again and send them directly to the site. The only clue I've been given is that it has to do with a check involving my welcome.js file:

let username = prompt('Enter your name') 
        fetch("/welcome/createuser", {
        method : "POST",
        headers: {
            "Content-Type" : "application/json"
        },
        body: username
    })
    .then((response) => response.json())
        .then(user =>
            sessionStorage.setItem("user",JSON.stringify(user)))

Any help would be appreciated at this moment. Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can check if the username is already in session before prompting the user to input a username

if(sessionStorage.getItem("user")){
   // set chat user to sessionStorage.getItem("user")
   let username = sessionStorage.getItem("user")
} else {
   let username = prompt("Enter your name");
   fetch("/welcome/createuser", {
      method: "POST",
      headers: {
      "Content-Type": "application/json",
      },
         body: username,
      })
   .then((response) => response.json())
   .then((user) => sessionStorage.setItem("user", JSON.stringify(user)));
}
   
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