Logout and delete data when user logs out of WordPress#150
Merged
Conversation
We're no longer prefixing local storage keys with a variable prefix.
On the next line we'll JSON-parse an undefined value which will retrun undefined, and we're already handling that case.
There are other entries in local storage for chatrix.
We'll delete data from local storage in next commits.
ashfame
approved these changes
Jan 4, 2023
Member
ashfame
left a comment
There was a problem hiding this comment.
Works well! 👏
I am curious if you ran into the need to load the logout JS code all the time as opposed to only doing it when the logout cookie is detected, as you wanted to do earlier?
Member
Author
|
That's a good point about only loading the logout JS when the cookie is detected, didn't even cross my mind. (Previously I mentioned only loading the logout JS code when needed, but I think that was before we settled on using a cookie.) I will look into this in another PR. |
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #118
Previously, before the move to using hydrogen internally instead of chatterbox, we implemented logging the user out from chatrix when they are not logged in to WordPress. This code was non-functional since the move to hydrogen.
The approach we took was to execute some JavaScript on all non-logged-in page loads. However, this approach prevents chatrix from being used without logging in to WordPress, since the user would be logged out from chatrix on every page load. Instead, the user should be logged out from chatrix only if a WordPress logout has happened.
That's the approach we take in this PR. We set a cookie on WordPress logout, then run some JavaScript if and only if that cookie exists. This allows for using chatrix without logging in to WordPress. Chatrix logout will still happen if the user subsequently logs in and out of WordPress.
Sumary of changes
src/tofrontend/, and add avitebuild for this which produces alogout.iife.jsbundle. This allows us to use TypeScript instead of vanilla JS.logout.iife.json all non-logged-in page loadschatrix-logoutcookie on WordPress logoutlogout.ts, check itchatrix-logoutcookie exists. If it does exist, logout all chatrix sessions, then delete all data in local storage and indexedDB.