Skip to content
Back

android kotlin error updatePhone

  • 0
  • Android
  • Auth
BAD BOY
25 Apr, 2025, 18:02

package vasu.apps.schooldashboard.Services

import android.util.Log import io.appwrite.Client import io.appwrite.ID import io.appwrite.exceptions.AppwriteException import io.appwrite.models.User import io.appwrite.services.Account

class AccountService(client: Client) { private val account = Account(client)

TypeScript
suspend fun getLoggedIn(): User<Map<String, Any>>? {
    return try {
        account.get()
    } catch (e: AppwriteException) {
        null
    }
}

suspend fun login(email: String, password: String): User<Map<String, Any>>? {
    return try {
        account.createEmailPasswordSession(email, password)
        getLoggedIn()
    } catch (e: AppwriteException) {
        null
    }
}

suspend fun register(
    email: String,
    password: String,
    name: String,
    phoneNumber: String, // e.g., "9876543210"
    label: String         // Custom label to be stored with phone number
): User<Map<String, Any>>? {
    return try {

        val sanitizedPhoneNumber = phoneNumber.filter { it.isDigit() }
        val fullPhoneNumber = "+91$sanitizedPhoneNumber"
        if (fullPhoneNumber.length > 15) {
            Log.e("AccountService", "Phone number exceeds 15 character limit: $fullPhoneNumber")
            return null
        }

        account.create(ID.unique(), email, password, name)
        val user = login(email, password)

        user?.let {
            account.updatePhone(user.id, fullPhoneNumber)
        }

        user
    } catch (e: AppwriteException) {
        Log.e("AccountService", e.message.toString())
    } as User<Map<String, Any>>?
}


suspend fun logout() {
    account.deleteSession("current")
}

}

in this i get error like this : E Invalid phone param: Phone number must start with a '+' can have a maximum of fifteen digits.

and i input the number like this : +911234567890

TL;DR
Developers should include user id and phone number as parameters for the `account.updatePhone()` function in Kotlin. Additionally, wrap code snippets in backticks for better formatting. The error "Invalid phone param: Phone number must start with a '+' can have a maximum of fifteen digits" occurs because the phone number inputted should start with a '+' sign and not exceed 15 characters. Make sure to follow these rules when inputting phone numbers.
Steven
25 Apr, 2025, 18:59

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting).

Steven
25 Apr, 2025, 18:59

account.updatePhone(user.id, fullPhoneNumber)

What told you to pass user id and phone number as the params?

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