Search code examples
flutterappwrite

Appwrite sms authentication connection times out


I want to enable phone authentication on my flutter app with appwrite. I followed the official guidelines, changed the .env variables of appwrite and used docker compose up -d to restart appwrite with the correct credentials. As SMS provider I am using text-magic therefore my .env file has the following configurations for sms:

_APP_SMS_PROVIDER=sms://[USERNAME]:[API-KEY]@text-magic
_APP_SMS_FROM=+123456789

Username and API-Key come from textmagic

Additionallly I've created a simple method to create a phone Session.

createPhoneSession(String phonenumber) async {
    try {
      Client client = Client();
      client
          .setEndpoint(AppConstants.endpointId)
          .setProject(AppConstants.projectId);
      Account account = Account(client);
      var token = await account.createPhoneSession(userId: ID.unique(), phone: phonenumber);
      print(token.$id);
    } catch (error) {
      print(error);
    }
  }

The exception I get is the following: I/flutter ( 5195): AppwriteException: null, Connection timed out (0)

Any suggestions why it keeps timing out? Thank you for your help in advance!


Solution

  • As you mentioned, the endpoint was incorrect. When developing locally, you can't use localhost for the endpoint because the mobile device will try to connect to itself rather than Appwrite. Instead of localhost, you can use your LAN IP.