-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logout and delete data when user logs out of WordPress #150
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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. |
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 avite
build for this which produces alogout.iife.js
bundle. This allows us to use TypeScript instead of vanilla JS.logout.iife.js
on all non-logged-in page loadschatrix-logout
cookie on WordPress logoutlogout.ts
, check itchatrix-logout
cookie exists. If it does exist, logout all chatrix sessions, then delete all data in local storage and indexedDB.