Im experimenting with random theme and "new technology" and Im trying to convert whole front-end to pure JS single page application (no page refreshes - like Facebook, Twitter etc) using WP REST API, Redux.js and React.js and few other helpers.
How to handle logged-in users? How do I keep track of that? I know that this information is normally handled with cookies. How would one check it via JS?
I could just make an ajax call every time route/url changes and use is_user_logged_in()
in server-side but it seems primative. Could I access directly to cookie via JS and check it in browser?
- I gave it a long thought if that's off-topic here but it really seems like a very WP specific question
- Im just experimenting and trying to push it to a new level, please no "this is a bad idea" comments
body_class()
haslogged-in
class which you could check for in JS. I think the best bet is to check all these things oninit
( or a similar hook ) and localize them to your JSwp_localize_script()
only checks if user is logged in if page is (re)loaded and might be invalid at some point in single page app (which doesn't require reloading). Im currently thinking if it's possible to: 1. Capture the session name if user logs in, is it possible? 2. Save it as user meta 3. Fetch it and save it as JS variable 4. Check if that session exists by name if needed (which is possible in JS) - e.g with every url/route change. Why I would need to capture the name? Because name (also value) is randomly generated.