I’m currently trying to figure out how to detect if a WordPress user is logged in when browsing the decoupled frontend (NextJS app, GraphQL via the WPGraphQL plugin) for showing options based on this, like an edit button for the current page. It’s a simple check on monolithic WordPress pages, but I’m clueless about doing it this way.
2
Answers
If a user is logged in there should be a key in the local or session storage you can check for. If it it populated that user is logged in. I would reach out to you team to learn what key to look for. Code for doing this would look similar to
https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem
Hacky, but if you have the default wp body class you can check it logged-in. Not tested, but shouuld work.
get_body_class has :