Works a treat if you refresh the page. However, when someone logs in and out it doesn’t refresh the page nor trigger the code to run / change the icons on the screen.
Any ideas on how to achieve this every time someone logs in and out?
Currently you perform a check during onReady so it’s executed when you load the page and there’re no checks performed later.
You can use wix-users onLogin API to handle changes when user successfullly logs in. For example set your icons in login box the way that it should work.
Regarding log out I don’t see anything in API to help handle this, unless you handle logout via code. In that case you can simply change login box after logout is complete. If that’s not the case you can also use something like native JavaScript setInterval method thus performing regular checks.
The interval options sounds like the better idea, that way I can continually test everything (then add a timeoutfunction to stop it after 10 seconds (should be complete by then)).
I’ve had a look at the link you sent to me, this seems like what I would need. Do you know how would I squeeze that into my code?
var intervalID = window.setInterval(myCallback, 500);
Many thanks for the help!
Alternatively, I’ve tried implementing the onLogin function which doesn’t seem to have worked either?
You can simply use setInterval function, without specifying window object.
var intervalID = setInterval(myCallback, 500);
onLogin function it works only when page is already ready, so in order for this to work you can set up onLogin handler inside onReady or afterwards there’s a small note in documentation that clarifies this.
Scratch that, didn’t quite work perfectly. It wasn’t checking if people were logged in if you closed the tab and re-entered so the displayed information was incorrect. It was almost the reverse of what I had before!
I’ve combined / smashed everything together now and it all seems to be working fine:
It changes when people login/logout, also checks for when people open the site in a new tab and displays the correct information.