Skip to content

Commit bad0a99

Browse files
Fix recovery bootstrap for emailpassword login param
Co-authored-by: Ray Jacobson <raymondjacobson@users.noreply.github.com>
1 parent 66cd36e commit bad0a99

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

packages/web/index.html

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,26 @@
7676
const lookupKey = urlParams.get('lookupKey')
7777
const hasEmail = Boolean(email)
7878
const hasLookupKey = Boolean(lookupKey)
79+
const isEmailPasswordRecovery = mode === 'emailpassword'
80+
81+
const decodeLoginEntropy = (loginValue) => {
82+
try {
83+
// Handle URL-safe base64 tokens and missing padding.
84+
const normalizedLogin = loginValue.replace(/-/g, '+').replace(/_/g, '/')
85+
const padding = '='.repeat((4 - (normalizedLogin.length % 4)) % 4)
86+
return atob(normalizedLogin + padding)
87+
} catch {
88+
return null
89+
}
90+
}
7991

80-
let entropy = null
8192
if (login) {
82-
entropy = atob(login)
83-
window.localStorage.setItem('hedgehog-entropy-key', entropy)
93+
if (!isEmailPasswordRecovery) {
94+
const entropy = decodeLoginEntropy(login)
95+
if (entropy) {
96+
window.localStorage.setItem('hedgehog-entropy-key', entropy)
97+
}
98+
}
8499
let redirectUrl = location.protocol + '//' + location.host
85100
if (useHashRouting) {
86101
redirectUrl += '/#'
@@ -89,7 +104,6 @@
89104
window.history.replaceState({}, document.title, redirectUrl)
90105
}
91106

92-
const isEmailPasswordRecovery = mode === 'emailpassword'
93107
const isPasswordRecovery =
94108
!isEmailPasswordRecovery &&
95109
(warning === 'RECOVERY_DO_NOT_SHARE' || mode === 'password')

0 commit comments

Comments
 (0)