CirclesUBI / circles-mobile

Circles react-native mobile client
GNU Affero General Public License v3.0
7 stars 2 forks source link

Feature/account recovery #72

Closed edzillion closed 5 years ago

edzillion commented 5 years ago

Equivalent PR on API https://github.com/CirclesUBI/circles-api/pull/78

FE

AuthSaga initRecoverAccount() signs a message (a timestamp) and sends to API. phone_number and device_id sent in case of phone number or device change.

        body: {
          message: message,
          signature: signature,
          device_id: DeviceInfo.getUniqueID(),
          phone_number: phone
        }

API

usersController.recoverAccount() logic overview:

  1. Check message to see if timestamp is less than 2.5 minutes old and not in the future. If fail then send 403
  2. recoverAddress() from message and signature
  3. Search DB for address. If not exist then send 404
  4. getSNSEndpoint() from aws sns
  5. If not exist or malformed then createSNSEndpoint()
  6. Else, if device_id has changed then updateSNSEndpoint
  7. Check if phone_number has changed then updatePhone() on aws cognito
  8. Save updated fields to DB
  9. Return updated user to FE

At this point the user is signed out and will need to sign in or even use forgot password to recover the login credentials.