-
Notifications
You must be signed in to change notification settings - Fork 2
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
Embedded key fixes #6
Conversation
Deploying with Cloudflare Pages
|
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.
One piece that's missing: initEmbeddedKey
should check for expir
index.html
Outdated
* DEBUG functionality only to reset the page's localStorage | ||
*/ | ||
document.getElementById("clear").addEventListener("click", TKHQ.clearEmbeddedKey); | ||
document.getElementById("reset").addEventListener("click", TKHQ.resetEmbeddedKey); | ||
}, false); |
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.
If we want an actual event to drive the reset let's have the button click trigger an event on the page like we do for other events:
https://github.com/tkhq/recovery/blob/ce33591723435a64be97830a2a492ef6f7e519a7/index.html#L776-L782
And then you can add another if statement in here to handle the reset case:
https://github.com/tkhq/recovery/blob/ce33591723435a64be97830a2a492ef6f7e519a7/index.html#L753-L762
That way the parent will be able to post a RESET message to an iframe, or we can trigger this even in the standalone page, and the exact same onReset
handler will be called.
btw |
index.html
Outdated
document.getElementById("reset").addEventListener("click", TKHQ.resetEmbeddedKey); | ||
document.getElementById("reset").addEventListener("click", async function(e) { | ||
e.preventDefault(); | ||
window.postMessage({ "type": "RESET_EMBEDDED_KEYSET" }) |
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.
- I think you're missing the event handler for this new event! We should now have a
onReset
oronClear
function to do this (you can renameresetEmbeddedKey
- The even name should be
RESET_EMBEDDED_KEY
(you have an extraSET
in there!)
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.
AH im just slipping today >_< thanks for catching this
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.
Nice! Looks ready to merge! One final tiny nitpicky thing
index.html
Outdated
getEmbeddedKey, | ||
setEmbeddedKey, | ||
clearEmbeddedKey, | ||
onResetEmbeddedKey, |
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.
Nit: I don't think this needs to be exported anymore!
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.
i originally kept it for the test, but i think we don't really need to test this unless we want to test all events. and we are already testing the underlying functionality for localStorage getter/setter. so i just removed this and its usage in the test!
TL;DR: 1 fix + 2 changes for the embedded key that is generated and stored in localStorage:
We want to avoid the nightmare situation where we have buggy keys in the user's localStorage. Rather than directing the user from manually debugging/clearing their localStorage, we can add 2 additional controls: 1) The parent page can post a
RESET_EMBEDDED_KEY
event that we listen to clear the key from localStorage. 2) The key is set in localStorage with an expiration of 48 hours. If it's expired when we're fetching it, we remove it from localStorage and return null. If it should have an expiration but is not saved with an expiration, we also remove it and return null.TODO: Maybe in a separate PR, we need to figure out a fix for