Skip to content

Instantly share code, notes, and snippets.

@Echooff3
Created January 19, 2023 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Echooff3/180d96140e7d4d564fa85f05912ebc60 to your computer and use it in GitHub Desktop.
Save Echooff3/180d96140e7d4d564fa85f05912ebc60 to your computer and use it in GitHub Desktop.
Very simple link expiration for React Aps
if(window.location.search.indexOf('key') > -1 )
{
try {
// Could probably do this better but I'm being lazy
const linkKey = window.location.href.toString().split('=')[1]
// Side effect of being lazy means I have to add back the 2 == at the end of the string I just split
var bytes = CryptoJS.AES.decrypt(linkKey + '==', KEY);
var originalText = bytes.toString(CryptoJS.enc.Utf8);
passUser = moment(originalText).valueOf() > moment().valueOf()
} catch (error) {
passUser = false;
}
}
if(!passUser) {
return <NoAccess />
} else {
<Access />
}
@Echooff3
Copy link
Author

If you need a down and dirty link expiration this code works just fine. However, someone savvy could reverse engineer it from inspecting the code. DO NOT USE FOR SENSITIVE INFO!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment