Heading not updating after logging in.

I have 2 variants of the handleSuccessfulLogin function but none of them work. I want to the update the heading in stats.html when the the user is logged in. It does direct to the page after logging in but doesnt add the "Welcome {username} on that page.
6 Replies
Aman
Aman13mo ago
Jochem
Jochem13mo ago
when you use window.location the page is reloaded and your javascript state and any modifications you made to the dom are lost you'll have to check if the user is logged in somehow on each fresh page load and change the dom accordingly. Considering this is all front-end, you can get away with just checking if the login cookie from the backend exists and changing the DOM accordingly
Aman
Aman13mo ago
Sorry but i don't know how to check on each page if the user is logged in or not. Can you please maybe tell me the steps to do it rather the full code?
Jochem
Jochem13mo ago
you're storing the username in sessionStorage:
sessionStorage.setItem('username', username);
sessionStorage.setItem('username', username);
On each page load, you can check if that is still set, and then change the DOM accordingly
Aman
Aman13mo ago
Alright, thanks It works now Thanks a lot.
Jochem
Jochem13mo ago
always glad to help!
Want results from more Discord servers?
Add your server
More Posts