Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions packages/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,26 @@
const lookupKey = urlParams.get('lookupKey')
const hasEmail = Boolean(email)
const hasLookupKey = Boolean(lookupKey)
const isEmailPasswordRecovery = mode === 'emailpassword'

const decodeLoginEntropy = (loginValue) => {
try {
// Handle URL-safe base64 tokens and missing padding.
const normalizedLogin = loginValue.replace(/-/g, '+').replace(/_/g, '/')
const padding = '='.repeat((4 - (normalizedLogin.length % 4)) % 4)
return atob(normalizedLogin + padding)
} catch {
return null
}
}

let entropy = null
if (login) {
entropy = atob(login)
window.localStorage.setItem('hedgehog-entropy-key', entropy)
if (!isEmailPasswordRecovery) {
const entropy = decodeLoginEntropy(login)
if (entropy) {
window.localStorage.setItem('hedgehog-entropy-key', entropy)
}
}
let redirectUrl = location.protocol + '//' + location.host
if (useHashRouting) {
redirectUrl += '/#'
Expand All @@ -89,7 +104,6 @@
window.history.replaceState({}, document.title, redirectUrl)
}

const isEmailPasswordRecovery = mode === 'emailpassword'
const isPasswordRecovery =
!isEmailPasswordRecovery &&
(warning === 'RECOVERY_DO_NOT_SHARE' || mode === 'password')
Expand Down
Loading