0

I'm trying to use the Appwrite SDK for Android to update a user's password in my Kotlin app. I'm using the following code, but the update doesn't seem to be happening:

binding.updatePasswordBtn.setOnClickListener {
    GlobalScope.launch(Dispatchers.Main) {
        try {
            val response = account.updatePassword(binding.password.text.toString())
            startActivity(Intent(this@UpdatePasswordActivity, LoginActivity::class.java))
            finish()
        } catch (e: AppwriteException) {
            Toast.makeText(this@UpdatePasswordActivity,e.message.toString(),Toast.LENGTH_SHORT).show()
        }
    }
}

account comes from the following object:

object AppwriteManager {
    lateinit var client: Client
    lateinit var account: Account

    fun initialize(context: Context) {
        client = Client(context)
            .setEndpoint("https://cloud.appwrite.io/v1")
            .setProject("648b14**************")
            .setSelfSigned(status = true)

        account = Account(client)
    }
}

I've added the following dependency to my code:

implementation("io.appwrite:sdk-for-android:2.0.0")

Any idea what I'm doing wrong?

Harsh Panchal
  • 146
  • 1
  • 1
  • 6
  • Assuming you are on the latest version, `updatePassword` is a suspending call. Try wrapping the method inside `withContext(Dispatchers.IO) {...}`. And `GlobalScope` should be replaced with appropriate lifecycle based scope. – Darshan Jun 17 '23 at 16:32
  • I'm on 2.0.x version of Appwrite SDK. They didn't added new versioned documentation yet. Also I downgraded the dependency version, getting exception message like "Invalid credentials. Please check email and password" – Harsh Panchal Jun 18 '23 at 07:01

1 Answers1

0

Version 2.0.0 of the Android SDK is for Appwrite version 1.3.x. You can always look at the README to see what version of Appwrite the SDK is for:

**This SDK is compatible with Appwrite server version 1.3.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).**

So, the docs are here.

Looking at your code, I'm going to assume it's throwing an error because you're not passing the oldPassword parameter:

    /**
     * Update Password
     *
     * Update currently logged in user password. For validation, user is required to pass in the new password, and the old password. For users created with OAuth, Team Invites and Magic URL, oldPassword is optional.
     *
     * @param password New user password. Must be at least 8 chars.
     * @param oldPassword Current user password. Must be at least 8 chars.
     * @return [io.appwrite.models.User<T>]
     */
    @JvmOverloads
    suspend fun <T> updatePassword(
        password: String,
        oldPassword: String? = null,
        nestedType: Class<T>,
    ): io.appwrite.models.User<T>
Steven Nguyen
  • 452
  • 4
  • 4