Skip to content

Commit

Permalink
Restart signup flow
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacsolo committed Nov 6, 2023
1 parent 5f46bc2 commit 7fcf4d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 9 additions & 1 deletion packages/identity-service/src/routes/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function (app) {
// Setting the option paranoid to true searches both soft-deleted and non-deleted objects
// https://sequelize.org/master/manual/paranoid.html
// https://sequelize.org/master/class/lib/model.js~Model.html#static-method-findAll
const existingRecord = await models.Authentication.findOne({
let existingRecord = await models.Authentication.findOne({
where: { lookupKey: body.lookupKey },
paranoid: false
})
Expand All @@ -40,6 +40,14 @@ module.exports = function (app) {
)
} else if (existingRecord.isSoftDeleted()) {
await existingRecord.restore({ transaction })
} else {
// old auth artifacts may not be recoverable
// restart sign up flow and overwrite existing auth artifacts
existingRecord = await existingRecord.update({
iv: body.iv,
cipherText: body.cipherText,
updatedAt: Date.now()
})
}

const oldLookupKey = body.oldLookupKey
Expand Down
16 changes: 14 additions & 2 deletions packages/identity-service/src/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,22 @@ module.exports = function (app) {
email: email
}
})

if (existingUser) {
const userEvent = await models.UserEvents.findOne({
where: {
walletAddress: existingUser.walletAddress
}
})
if (!userEvent && !existingUser.handle) {
// user does not have recovery email nor handle
// delete existing user record to restart sign up
existingUser.destroy()
return successResponse({ exists: false })
}
return successResponse({ exists: true })
} else return successResponse({ exists: false })
} else {
return successResponse({ exists: false })
}
} else
return errorResponseBadRequest('Please pass in a valid email address')
})
Expand Down

0 comments on commit 7fcf4d3

Please sign in to comment.