Refresh Required when Posting to /login

  • When a player accesses our forums we're checking if a cookie exists on the client and if it does we send a post to /login to log the player in using our existing accounts system. The login works but it requires a refresh to show the player as logged in. Is there some event I should be listening for, or some signal I should be sending to the client to force it to update?

  • Community Rep

    Maybe this. If the cookie exists, you could make a socket event e.g., 'login:playername' on the client before you send the login, then fire it from the server after the login is complete. Only the client with the cookie will run the event, and in the event you can refresh the browser.

  • Community Rep

    Or actually, doesn't the server see the cookie before it sends the page? There's probably a way to use middleware to check the cookie and login before the server sends the reply. Maybe the hook 'action:middleware.authenticate', never used it, but it sounds like it may be useful.

  • If there is a hook to use during connection/cookie check on the server side I'll gladly use it. That hook though doesn't seem to fire on its own.

  • @overlawled I think I was over-thinking it.

    How are you sending the post request? Could you just wait for the response code and refresh the page if it's 200?

  • Yep, and that's indeed what I've ended up doing. It doesn't feel as nice as it could be but it will do.

Suggested Topics

| | | |