Back

save user phone immediately, during create account

  • 0
  • Flutter
  • Accounts
safwan
19 Mar, 2023, 04:33

Hey @dammy, could you create a gist with your full code? Happy to take a look and try to figure out a solution!

TL;DR
The user is having trouble adding a phone number during the account creation process. They are considering altering the SDK file or adding phone verification after login. It is recommended to redirect the user to add a phone number after registration. The user is also advised to create a session and ensure that the `create()` function is fully finished before calling the `updatePhone()` function. There is a suggestion to check for the use of futures and async programming. Additionally, the user is advised to ensure that the `createAcc()` and `addPhoneDetails()` methods have a return type of `Future` and provide a full code sample for further assistance.
safwan
19 Mar, 2023, 04:40

based off of this, your createAcc() and addPhoneDetails() methods don't have a return type.

This isn't the best way to do this because: in createAcc, you're returning the response, and if there's an error, you're returning a string. Those are two different types of Future:

TypeScript
submitDetails.then((response) {
      if (response.statusCode == 201) {
        debugPrint("successful");
      }

      return response;
    }).catchError((error) {
      return "An error occured";
    });

How to resolve this? Try adding a return type of Future to the createAcc function. This will make sure that whatever gets, returned by the function, is of the type Future<something>. Then you can use await createAcc();. This should work because the function will wait for something to be returned; and that's when you use Future - when the returned value is computed/fetched after some time.

Do the same for the addPhoneDetails(), and see if it works. Let me know if there's any issues!

dammy
19 Mar, 2023, 15:53

okay, but originally, submitDetails works, just addPhoneDetails() that is not adding phone number

Drake
19 Mar, 2023, 15:56

Btw, response doesn't have a statusCode. I'm surprised your IDE isn't telling you that's a problem

Drake
19 Mar, 2023, 15:57

Anyways, again, this comes down to futures and async programming. This is the same problem you're having: https://dart.dev/codelabs/async-await#example-incorrectly-using-an-asynchronous-function

account.create() is not finishing fully before you can account.updatePhone

dammy
19 Mar, 2023, 15:57

I did this

Drake
19 Mar, 2023, 15:58

Good. And?

dammy
19 Mar, 2023, 15:58

account.create() is not finishing fully before you can account.updatePhone

I will check for this again

dammy
19 Mar, 2023, 15:58

same issue

Drake
19 Mar, 2023, 15:59

What's the full error you're seeing now?

dammy
19 Mar, 2023, 15:59

the thing is, it is not adding phone number

Drake
19 Mar, 2023, 16:01

Oh right....again you don't have a session. You need to create a session

dammy
19 Mar, 2023, 16:01

ouch, no wonder

dammy
19 Mar, 2023, 16:01

you mean login?

dammy
19 Mar, 2023, 16:04

so, you mean during registration, phone can not be added?

dammy
19 Mar, 2023, 16:04

here it is

dammy
19 Mar, 2023, 16:05

because, I want to do email and phone verification in parallel

Drake
19 Mar, 2023, 16:06

As part of the API, create account does not have a phone parameter.

dammy
19 Mar, 2023, 16:06

that means I will request for phone after login?

dammy
19 Mar, 2023, 16:07

or is it advisable to alter the sdk file?

safwan
19 Mar, 2023, 16:07

not a good practice, and not recommended. You can register the user, then redirect them to add a phone number immediately after

dammy
19 Mar, 2023, 16:08

ok then

dammy
19 Mar, 2023, 16:08

Thanks man

safwan
19 Mar, 2023, 16:08

no worries at all

dammy
19 Mar, 2023, 16:20

I appreciate you all @safwan and @Steven

you all are the best, thanks for been of great help

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more