Skip to content

Commit

Permalink
WIP: Fast-path login
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Feb 9, 2025
1 parent a64f8e0 commit 3c1c64e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
36 changes: 18 additions & 18 deletions frontend/controller/actions/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,28 +411,28 @@ export default (sbp('sbp/selectors/register', {
await processOldIekList(identityContractID, oldKeysAnchorCid, transientSecretKeys[0].key)
}

try {
if (!state) {
// Make sure we don't unsubscribe from our own identity contract
// Note that this should be done _after_ calling
// `chelonia/storeSecretKeys`: If the following line results in
// syncing the identity contract and fetching events, the secret keys
// for processing them will not be available otherwise.
await sbp('chelonia/contract/retain', identityContractID)
} else {
// If there is a state, we've already retained the identity contract
// but might need to fetch the latest events
await sbp('chelonia/contract/sync', identityContractID)
}
} catch (e) {
console.error('[gi.actions/identity] Error during login contract sync', e)
throw new GIErrorUIRuntimeError(L('Error during login contract sync'), { cause: e })
}

try {
await sbp('gi.db/settings/save', SETTING_CURRENT_USER, identityContractID)
sbp('okTurtles.events/emit', LOGIN, { identityContractID, encryptionParams, state })

try {
if (!state) {
// Make sure we don't unsubscribe from our own identity contract
// Note that this should be done _after_ calling
// `chelonia/storeSecretKeys`: If the following line results in
// syncing the identity contract and fetching events, the secret keys
// for processing them will not be available otherwise.
await sbp('chelonia/contract/retain', identityContractID)
} else {
// If there is a state, we've already retained the identity contract
// but might need to fetch the latest events
await sbp('chelonia/contract/sync', identityContractID)
}
} catch (e) {
console.error('[gi.actions/identity] Error during login contract sync', e)
throw new GIErrorUIRuntimeError(L('Error during login contract sync'), { cause: e })
}

const contractIDs = groupContractsByType(cheloniaState?.contracts)
await syncContractsInOrder(contractIDs)

Expand Down
2 changes: 1 addition & 1 deletion frontend/controller/app/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ sbp('okTurtles.events/on', LOGIN, async ({ identityContractID, encryptionParams,
// NOTE: users could notice that they leave the group by someone
// else when they log in
const currentState = sbp('state/vuex/state')
if (!currentState.currentGroupId) {
if (!currentState.currentGroupId && currentState[identityContractID]) {
const gId = Object.keys(currentState.contracts)
.find(cID => currentState[identityContractID].groups[cID] && !currentState[identityContractID].groups[cID].hasLeft)

Expand Down

0 comments on commit 3c1c64e

Please sign in to comment.