All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.supertokens.sdk.recipes.emailverification.usecases.VerifyEmailUseCase.kt Maven / Gradle / Ivy

The newest version!
package com.supertokens.sdk.recipes.emailverification.usecases

import com.supertokens.sdk.common.Routes
import com.supertokens.sdk.common.SuperTokensStatus
import com.supertokens.sdk.common.requests.VerifyEmailTokenRequestDTO
import com.supertokens.sdk.common.responses.StatusResponseDTO
import com.supertokens.sdk.common.toStatus
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.appendEncodedPathSegments

internal class VerifyEmailUseCase(
    private val client: HttpClient,
    private val tenantId: String?,
) {

  suspend fun verifyEmail(token: String): Boolean {
    val response =
        client.post {
          url {
            appendEncodedPathSegments(
                listOfNotNull(
                    tenantId,
                    Routes.EmailVerification.VERIFY,
                ))
          }
          setBody(
              VerifyEmailTokenRequestDTO(
                  token = token,
              ))
        }

    val body = response.body()

    return body.status.toStatus() == SuperTokensStatus.OK
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy