Fix account linking issues (#128)

Everything's looking good/working well 👌🏼 Nice catch 🙏🏼
This commit is contained in:
Brian Ginsburg 2023-06-20 11:11:52 -07:00 committed by GitHub
parent 1457d6b744
commit 506172ed12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -122,3 +122,32 @@ export const loadAccount = async (hashedUsername: string, fullUsername: string):
backupCreated: backupStatus.created
}))
}
export async function waitForDataRoot(username: string): Promise<void> {
const session = getStore(sessionStore)
const reference = session.program?.components.reference
const EMPTY_CID = 'Qmc5m94Gu7z62RC8waSKkZUrCCBJPyHbkpmGzEePxy2oXJ'
if (!reference) throw new Error('Program must be initialized to check for data root')
let dataRoot = await reference.dataRoot.lookup(username)
if (dataRoot.toString() !== EMPTY_CID) return
return new Promise((resolve) => {
const maxRetries = 50
let attempt = 0
const dataRootInterval = setInterval(async () => {
dataRoot = await reference.dataRoot.lookup(username)
if (dataRoot.toString() === EMPTY_CID && attempt < maxRetries) {
attempt++
return
}
clearInterval(dataRootInterval)
resolve()
}, 500)
})
}

View File

@ -6,6 +6,8 @@
import { addNotification } from '$lib/notifications'
import { createAccountLinkingConsumer } from '$lib/auth/linking'
import { loadAccount } from '$lib/auth/account'
import { sessionStore } from '../../stores'
import { waitForDataRoot } from '$lib/auth/account'
import type { LinkDeviceView } from '$lib/views'
import FilesystemActivity from '$components/common/FilesystemActivity.svelte'
import LinkDevice from '$components/auth/link-device/LinkDevice.svelte'
@ -33,6 +35,8 @@
if (approved) {
view = 'load-filesystem'
// See https://github.com/oddsdk/ts-odd/issues/529
await waitForDataRoot(hashedUsername)
await loadAccount(hashedUsername, fullUsername)
addNotification("You're now connected!", 'success')
@ -51,7 +55,9 @@
goto('/')
}
initAccountLinkingConsumer()
if (!$sessionStore.session) {
initAccountLinkingConsumer()
}
</script>
<input type="checkbox" id="my-modal-5" checked class="modal-toggle" />