Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 11 additions & 3 deletions packages/common/src/services/auth/authService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ export type AuthService = {
signOut: () => Promise<void>
resetPassword: ({
username,
password
password,
oldLookupKey
}: {
username: string
password: string
oldLookupKey?: string
}) => Promise<void>
getWallet: () => EthWallet | null
generateRecoveryInfo: () => Promise<{ login: string; host: string }>
Expand Down Expand Up @@ -84,12 +86,18 @@ export const createAuthService = ({

const resetPassword = async ({
username,
password
password,
oldLookupKey
}: {
username: string
password: string
oldLookupKey?: string
}) => {
return hedgehogInstance.resetPassword({ username, password })
return hedgehogInstance.resetPassword({
username,
password,
oldLookupKey
})
}

const generateRecoveryInfo = async () => {
Expand Down
41 changes: 38 additions & 3 deletions packages/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@
<script async type="text/javascript">
// Account recovery
try {
const RESET_REQUIRED_KEY = 'password-reset-required'
const urlParams = new URLSearchParams(window.location.search)
const useHashRouting = '%USE_HASH_ROUTING%' === 'true'
const login = urlParams.get('login')
const warning = urlParams.get('warning')
const mode = urlParams.get('mode')
const email = urlParams.get('email')
const lookupKey = urlParams.get('lookupKey')
const hasEmail = Boolean(email)
const hasLookupKey = Boolean(lookupKey)

let entropy = null
if (login) {
Expand All @@ -82,9 +88,38 @@
redirectUrl += location.pathname
window.history.replaceState({}, document.title, redirectUrl)
}
if (warning === 'RECOVERY_DO_NOT_SHARE') {
const email = urlParams.get('email')
window.localStorage.setItem('password-reset-required', email)

const isEmailPasswordRecovery = mode === 'emailpassword'
const isPasswordRecovery =
!isEmailPasswordRecovery &&
(warning === 'RECOVERY_DO_NOT_SHARE' || mode === 'password')
const isRecoveryMode = isPasswordRecovery || isEmailPasswordRecovery

if (isRecoveryMode) {
let resetPayload = null

if (isEmailPasswordRecovery && hasLookupKey) {
resetPayload = {
mode: 'emailpassword',
email: email ?? undefined,
lookupKey
}
} else if (isPasswordRecovery && hasEmail) {
resetPayload = {
mode: 'password',
email
}
}

if (resetPayload) {
window.localStorage.setItem(
RESET_REQUIRED_KEY,
JSON.stringify(resetPayload)
)
} else {
window.localStorage.removeItem(RESET_REQUIRED_KEY)
}

let redirectUrl = location.protocol + '//' + location.host
if (useHashRouting) {
redirectUrl += '/#'
Expand Down
9 changes: 9 additions & 0 deletions packages/web/src/common/store/pages/signon/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const { toast } = toastActions

const SIGN_UP_TIMEOUT_MILLIS = 20 /* min */ * 60 * 1000
const DEFAULT_HANDLE_VERIFICATION_TIMEOUT_MILLIS = 5_000
const PASSWORD_RESET_REQUIRED_KEY = 'password-reset-required'

const messages = {
incompleteAccount:
Expand All @@ -107,6 +108,11 @@ const messages = {
'Your account has been deactivated. Please contact support.'
}

const hasPendingPasswordReset = () => {
if (typeof window === 'undefined') return false
return Boolean(window.localStorage.getItem(PASSWORD_RESET_REQUIRED_KEY))
}

function* getDefautFollowUserIds() {
const { ENVIRONMENT } = yield* getContext('env')
// Users ID to filter out of the suggested artists to follow list and to follow by default
Expand Down Expand Up @@ -958,6 +964,9 @@ function* signIn(action: ReturnType<typeof signOnActions.signIn>) {
yield* put(requestPushNotificationPermissions())
} else {
setHasRequestedBrowserPermission()
while (hasPendingPasswordReset()) {
yield* delay(500)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what this do?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two modals popping up at once

}
yield* put(accountActions.showPushNotificationConfirmation())
if (user.handle === 'fbtest') {
yield put(pushRoute('/fb/share'))
Expand Down
Loading
Loading