Fix account linking issues (#128)
Everything's looking good/working well 👌🏼 Nice catch 🙏🏼
This commit is contained in:
parent
1457d6b744
commit
506172ed12
|
|
@ -122,3 +122,32 @@ export const loadAccount = async (hashedUsername: string, fullUsername: string):
|
||||||
backupCreated: backupStatus.created
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@
|
||||||
import { addNotification } from '$lib/notifications'
|
import { addNotification } from '$lib/notifications'
|
||||||
import { createAccountLinkingConsumer } from '$lib/auth/linking'
|
import { createAccountLinkingConsumer } from '$lib/auth/linking'
|
||||||
import { loadAccount } from '$lib/auth/account'
|
import { loadAccount } from '$lib/auth/account'
|
||||||
|
import { sessionStore } from '../../stores'
|
||||||
|
import { waitForDataRoot } from '$lib/auth/account'
|
||||||
import type { LinkDeviceView } from '$lib/views'
|
import type { LinkDeviceView } from '$lib/views'
|
||||||
import FilesystemActivity from '$components/common/FilesystemActivity.svelte'
|
import FilesystemActivity from '$components/common/FilesystemActivity.svelte'
|
||||||
import LinkDevice from '$components/auth/link-device/LinkDevice.svelte'
|
import LinkDevice from '$components/auth/link-device/LinkDevice.svelte'
|
||||||
|
|
@ -33,6 +35,8 @@
|
||||||
if (approved) {
|
if (approved) {
|
||||||
view = 'load-filesystem'
|
view = 'load-filesystem'
|
||||||
|
|
||||||
|
// See https://github.com/oddsdk/ts-odd/issues/529
|
||||||
|
await waitForDataRoot(hashedUsername)
|
||||||
await loadAccount(hashedUsername, fullUsername)
|
await loadAccount(hashedUsername, fullUsername)
|
||||||
|
|
||||||
addNotification("You're now connected!", 'success')
|
addNotification("You're now connected!", 'success')
|
||||||
|
|
@ -51,7 +55,9 @@
|
||||||
goto('/')
|
goto('/')
|
||||||
}
|
}
|
||||||
|
|
||||||
initAccountLinkingConsumer()
|
if (!$sessionStore.session) {
|
||||||
|
initAccountLinkingConsumer()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<input type="checkbox" id="my-modal-5" checked class="modal-toggle" />
|
<input type="checkbox" id="my-modal-5" checked class="modal-toggle" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue