diff --git a/auth/build.gradle.kts b/auth/build.gradle.kts index ce5ab0b..7a0c937 100644 --- a/auth/build.gradle.kts +++ b/auth/build.gradle.kts @@ -1,5 +1,5 @@ -import java.util.Date import com.jfrog.bintray.gradle.tasks.BintrayUploadTask +import java.util.* plugins { id("com.android.library") diff --git a/auth/src/androidMain/kotlin/com/liftric/base/Environment.kt b/auth/src/androidMain/kotlin/com/liftric/base/Environment.kt index 0954f98..6d972da 100644 --- a/auth/src/androidMain/kotlin/com/liftric/base/Environment.kt +++ b/auth/src/androidMain/kotlin/com/liftric/base/Environment.kt @@ -1,6 +1,6 @@ package com.liftric.base -actual class Environment { +actual internal class Environment { actual companion object { actual fun variable(value: String): String? { return System.getenv(value) diff --git a/auth/src/commonMain/kotlin/com/liftric/Auth.kt b/auth/src/commonMain/kotlin/com/liftric/Auth.kt index e3e36bc..d755e15 100644 --- a/auth/src/commonMain/kotlin/com/liftric/Auth.kt +++ b/auth/src/commonMain/kotlin/com/liftric/Auth.kt @@ -10,7 +10,7 @@ interface Auth { * @param attributes * @param response Callback with error if something went wrong or an object on success */ - suspend fun signUp(username: String, password: String, attributes: List? = null, response: (error: Error?, value: SignUpResponse?) -> Unit) + suspend fun signUp(username: String, password: String, attributes: List? = null): Result /** * Signs in the user with the given parameters @@ -18,21 +18,21 @@ interface Auth { * @param password The password * @param response Callback with error if something went wrong or an object on success */ - suspend fun signIn(username: String, password: String, response: (error: Error?, value: SignInResponse?) -> Unit) + suspend fun signIn(username: String, password: String): Result /** * Signs out the user globally * @param accessToken The access token from the sign in request * @param response Callback with error if something went wrong */ - suspend fun signOut(accessToken: String, response: (error: Error?) -> Unit) + suspend fun signOut(accessToken: String): Result /** * Fetches the user object * @param accessToken The access token from the sign in request * @param response Callback with error if something went wrong or an object on success */ - suspend fun getUser(accessToken: String, response: (error: Error?, value: GetUserResponse?) -> Unit) + suspend fun getUser(accessToken: String): Result /** * Updates the users attributes @@ -41,7 +41,7 @@ interface Auth { * @param attributes List of attributes that should be updated * @param response Callback with error if something went wrong or an object on success */ - suspend fun updateUserAttributes(accessToken: String, attributes: List, response: (error: Error?, value: UpdateUserAttributesResponse?) -> Unit) + suspend fun updateUserAttributes(accessToken: String, attributes: List): Result /** * Changes the password of the current user @@ -50,12 +50,12 @@ interface Auth { * @param newPassword The new password * @param response Callback with request response error */ - suspend fun changePassword(accessToken: String, currentPassword: String, newPassword: String, response: (error: Error?) -> Unit) + suspend fun changePassword(accessToken: String, currentPassword: String, newPassword: String): Result /** * Deletes the users account * @param accessToken The access token from the sign in request * @param response Callback with error if something went wrong */ - suspend fun deleteUser(accessToken: String, response: (error: Error?) -> Unit) + suspend fun deleteUser(accessToken: String): Result } diff --git a/auth/src/commonMain/kotlin/com/liftric/AuthHandler.kt b/auth/src/commonMain/kotlin/com/liftric/AuthHandler.kt index 4bd2b44..841e571 100644 --- a/auth/src/commonMain/kotlin/com/liftric/AuthHandler.kt +++ b/auth/src/commonMain/kotlin/com/liftric/AuthHandler.kt @@ -1,16 +1,16 @@ package com.liftric import com.liftric.base.* -import io.ktor.client.HttpClient -import io.ktor.client.features.defaultRequest -import io.ktor.client.request.header -import io.ktor.client.request.post -import io.ktor.client.statement.HttpResponse -import io.ktor.client.statement.readBytes -import io.ktor.http.ContentType -import io.ktor.http.contentType -import io.ktor.utils.io.core.String -import kotlinx.coroutines.* +import io.ktor.client.* +import io.ktor.client.features.* +import io.ktor.client.request.* +import io.ktor.client.statement.* +import io.ktor.http.* +import io.ktor.utils.io.core.* +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.Serializable +import kotlinx.serialization.SerializationException +import kotlinx.serialization.serializer /** * Authentifaction handler for AWS Cognito @@ -36,10 +36,9 @@ open class AuthHandler(private val configuration: Configuration) : Auth { override suspend fun signUp( username: String, password: String, - attributes: List?, - response: (error: Error?, value: SignUpResponse?) -> Unit - ) { - request( + attributes: List? + ): Result { + val response = request( RequestType.signUp, serialize( SignUp.serializer(), @@ -50,17 +49,23 @@ open class AuthHandler(private val configuration: Configuration) : Auth { UserAttributes = attributes ?: listOf() ) ) - ) { error, value -> - response(error, value?.let { parse(SignUpResponse.serializer(), it) }) + ) + return if (response.isSuccess) { + try { + Result.success(parse(SignUpResponse.serializer(), response.getOrNull()!!)) + } catch (e: SerializationException) { + Result.failure(e) + } + } else { + Result.failure(response.exceptionOrNull()!!) } } override suspend fun signIn( username: String, - password: String, - response: (error: Error?, value: SignInResponse?) -> Unit - ) { - request( + password: String + ): Result { + val response = request( RequestType.signIn, serialize( Authentication.serializer(), @@ -70,79 +75,80 @@ open class AuthHandler(private val configuration: Configuration) : Auth { AuthParameters(username, password) ) ) - ) { error, value -> - response(error, value?.let { parse(SignInResponse.serializer(), it) }) + ) + return if (response.isSuccess) { + try { + Result.success(parse(SignInResponse.serializer(), response.getOrNull()!!)) + } catch (e: SerializationException) { + Result.failure(e) + } + } else { + Result.failure(response.exceptionOrNull()!!) } } - override suspend fun deleteUser( - accessToken: String, - response: (error: Error?) -> Unit - ) { - request( - RequestType.deleteUser, + override suspend fun signOut(accessToken: String): Result { + val response = request( + RequestType.signOut, serialize( AccessToken.serializer(), AccessToken(accessToken) ) - ) { error, _ -> - response(error) + ) + return if (response.isSuccess) { + Result.success(Unit) + } else { + Result.failure(response.exceptionOrNull()!!) } } - override suspend fun getUser( - accessToken: String, - response: (error: Error?, value: GetUserResponse?) -> Unit - ) { - request( + override suspend fun getUser(accessToken: String): Result { + val response = request( RequestType.getUser, serialize( AccessToken.serializer(), AccessToken(accessToken) ) - ) { error, value -> - response(error, value?.let { parse(GetUserResponse.serializer(), it) }) - } - } - - override suspend fun signOut( - accessToken: String, - response: (error: Error?) -> Unit - ) { - request( - RequestType.signOut, - serialize( - AccessToken.serializer(), - AccessToken(accessToken) - ) - ) { error, _ -> - response(error) + ) + return if (response.isSuccess) { + try { + Result.success(parse(GetUserResponse.serializer(), response.getOrNull()!!)) + } catch (e: SerializationException) { + Result.failure(e) + } + } else { + Result.failure(response.exceptionOrNull()!!) } } override suspend fun updateUserAttributes( accessToken: String, - attributes: List, - response: (error: Error?, value: UpdateUserAttributesResponse?) -> Unit - ) { - request( + attributes: List + ): Result { + val response = request( RequestType.updateUserAttributes, serialize( UpdateUserAttributes.serializer(), UpdateUserAttributes(accessToken, attributes) ) - ) { error, value -> - response(error, value?.let { parse(UpdateUserAttributesResponse.serializer(), it) }) + ) + return if (response.isSuccess) { + try { + Result.success(parse(UpdateUserAttributesResponse.serializer(), response.getOrNull()!!)) + } catch (e: SerializationException) { + Result.failure(e) + } + } else { + Result.failure(response.exceptionOrNull()!!) } } override suspend fun changePassword( accessToken: String, currentPassword: String, - newPassword: String, - response: (error: Error?) -> Unit - ) { - request( + newPassword: String + ): Result { + val response = request( RequestType.changePassword, serialize( ChangePassword.serializer(), @@ -153,8 +159,26 @@ open class AuthHandler(private val configuration: Configuration) : Auth { newPassword ) ) - ) { error, _ -> - response(error) + ) + return if (response.isSuccess) { + Result.success(Unit) + } else { + Result.failure(response.exceptionOrNull()!!) + } + } + + override suspend fun deleteUser(accessToken: String): Result { + val response = request( + RequestType.deleteUser, + serialize( + AccessToken.serializer(), + AccessToken(accessToken) + ) + ) + return if (response.isSuccess) { + Result.success(Unit) + } else { + Result.failure(response.exceptionOrNull()!!) } } @@ -162,11 +186,7 @@ open class AuthHandler(private val configuration: Configuration) : Auth { // REQUEST //---------- - private suspend fun request( - type: RequestType, - payload: String, - completion: (error: Error?, value: String?) -> Unit - ) { + private suspend fun request(type: RequestType, payload: String): Result { val response = client.post(configuration.requestUrl) { header( Header.AmzTarget, @@ -185,12 +205,11 @@ open class AuthHandler(private val configuration: Configuration) : Auth { ) body = payload } - return if (response.status.value == 200) { - completion(null, String(response.readBytes())) + Result.success(String(response.readBytes())) } else { val error = parse(RequestError.serializer(), String(response.readBytes())) - completion(Error(error.message), null) + Result.failure(Error(error.message)) } } } diff --git a/auth/src/commonMain/kotlin/com/liftric/base/Environment.kt b/auth/src/commonMain/kotlin/com/liftric/base/Environment.kt index 475db97..a451b25 100644 --- a/auth/src/commonMain/kotlin/com/liftric/base/Environment.kt +++ b/auth/src/commonMain/kotlin/com/liftric/base/Environment.kt @@ -1,6 +1,6 @@ package com.liftric.base -expect class Environment() { +expect internal class Environment() { companion object { /** * Accesses environment variable diff --git a/auth/src/commonMain/kotlin/com/liftric/base/Payload.kt b/auth/src/commonMain/kotlin/com/liftric/base/Payload.kt index 031781f..2a02a15 100644 --- a/auth/src/commonMain/kotlin/com/liftric/base/Payload.kt +++ b/auth/src/commonMain/kotlin/com/liftric/base/Payload.kt @@ -3,32 +3,32 @@ package com.liftric.base import kotlinx.serialization.Serializable @Serializable -data class Authentication( +internal data class Authentication( val AuthFlow: String, val ClientId: String, val AuthParameters: AuthParameters ) @Serializable -data class AuthParameters( +internal data class AuthParameters( val USERNAME: String, val PASSWORD: String ) @Serializable -data class AccessToken( +internal data class AccessToken( val AccessToken: String ) @Serializable -data class ChangePassword( +internal data class ChangePassword( val AccessToken: String, val PreviousPassword: String, val ProposedPassword: String ) @Serializable -data class SignUp( +internal data class SignUp( val ClientId: String, val Password: String, val Username: String, @@ -42,7 +42,7 @@ data class UserAttribute( ) @Serializable -data class UpdateUserAttributes( +internal data class UpdateUserAttributes( val AccessToken: String, val UserAttributes: List ) \ No newline at end of file diff --git a/auth/src/commonMain/kotlin/com/liftric/base/Response.kt b/auth/src/commonMain/kotlin/com/liftric/base/Response.kt index 5b46d1a..6fea2ca 100644 --- a/auth/src/commonMain/kotlin/com/liftric/base/Response.kt +++ b/auth/src/commonMain/kotlin/com/liftric/base/Response.kt @@ -23,6 +23,7 @@ data class AuthenticationResult( val RefreshToken: String = "", val TokenType: String = "" ) + // Sign up @Serializable @@ -61,4 +62,4 @@ data class MFAOptions( @Serializable data class UpdateUserAttributesResponse( val CodeDeliveryDetailsList: List = listOf() -) \ No newline at end of file +) diff --git a/auth/src/commonMain/kotlin/com/liftric/base/Result.kt b/auth/src/commonMain/kotlin/com/liftric/base/Result.kt new file mode 100644 index 0000000..f57bd5f --- /dev/null +++ b/auth/src/commonMain/kotlin/com/liftric/base/Result.kt @@ -0,0 +1,29 @@ +package com.liftric.base + +class Result constructor(val value: Any?) { + val isSuccess: Boolean get() = value !is Failure + val isFailure: Boolean get() = value is Failure + + companion object { + fun success(value: T): Result = Result(value) + fun failure(exception: Throwable): Result = Result(Failure(exception)) + } + + class Failure(val exception: Throwable) { + override fun equals(other: Any?): Boolean = other is Failure && exception == other.exception + override fun hashCode(): Int = exception.hashCode() + override fun toString(): String = "Failure($exception)" + } + + fun getOrNull(): T? = + when { + isFailure -> null + else -> value as T + } + + fun exceptionOrNull(): Throwable? = + when (value) { + is Failure -> value.exception + else -> null + } +} diff --git a/auth/src/commonMain/kotlin/com/liftric/base/Serialization.kt b/auth/src/commonMain/kotlin/com/liftric/base/Serialization.kt index ef151ca..fa9f6cb 100644 --- a/auth/src/commonMain/kotlin/com/liftric/base/Serialization.kt +++ b/auth/src/commonMain/kotlin/com/liftric/base/Serialization.kt @@ -4,13 +4,13 @@ import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.json.Json -fun serialize(strategy: SerializationStrategy, value: T): String { +internal fun serialize(strategy: SerializationStrategy, value: T): String { return Json { allowStructuredMapKeys = true }.encodeToString(strategy, value) } -fun parse(strategy: DeserializationStrategy, value: String): T { +internal fun parse(strategy: DeserializationStrategy, value: String): T { return Json { allowStructuredMapKeys = true }.decodeFromString(strategy, value) diff --git a/auth/src/commonTest/kotlin/com/liftric/AuthHandlerIntegrationTests.kt b/auth/src/commonTest/kotlin/com/liftric/AuthHandlerIntegrationTests.kt index e14a619..8f4a405 100644 --- a/auth/src/commonTest/kotlin/com/liftric/AuthHandlerIntegrationTests.kt +++ b/auth/src/commonTest/kotlin/com/liftric/AuthHandlerIntegrationTests.kt @@ -25,17 +25,17 @@ class AuthHandlerIntegrationTests() { // INTEGRATION TESTS //------------------- - data class Credential(val username: String, val password: String) + data class Credentials(val username: String, val password: String) - private fun randomUser(): Credential { + private fun randomUser(): Credentials { val random = (0..999).random() - return Credential( + return Credentials( username = "auth-lib-test-user-${random}", password = "auth-lib-test-user-${random}A1@" ) } - private suspend fun createUser(block: (accessToken: String, credential: Credential) -> Unit) { + private suspend fun createUser(): Pair { val credential = randomUser() val userAttributes: List = listOf( UserAttribute( @@ -43,86 +43,75 @@ class AuthHandlerIntegrationTests() { Value = "ROLE_PATIENT" ) ) - authHandler.signUp(credential.username, credential.password, userAttributes) { error, value -> - assertNull(error) - assertNotNull(value) - } - authHandler.signIn(credential.username, credential.password) { _, value -> - assertNotNull(value) - block(value.AuthenticationResult.AccessToken, credential) - } + val signUpResponse = authHandler.signUp(credential.username, credential.password, userAttributes) + + assertNull(signUpResponse.exceptionOrNull()) + assertNotNull(signUpResponse.getOrNull()) + + val signInResponse = authHandler.signIn(credential.username, credential.password) + assertNotNull(signInResponse.getOrNull()) + + return Pair(signInResponse.getOrNull()!!.AuthenticationResult.AccessToken, credential) } private suspend fun deleteUser(token: String) { - authHandler.deleteUser(token) { error -> - assertNull(error) - } + val deleteUserResponse = authHandler.deleteUser(token) + assertNull(deleteUserResponse.exceptionOrNull()) } @JsName("SignUpSignInDeleteUserTest") @Test fun `Sign up, sign in, delete user should succeed`() = runBlocking { - authHandler.signUp( + val signUpResponse = authHandler.signUp( username, password, attributes = listOf( UserAttribute(Name = "email", Value = "test@test.test"), UserAttribute(Name = "custom:target_group", Value = "ROLE_USER") ) - ) { error, value -> - assertNull(error) - assertNotNull(value) - } - var accessToken: String = "" - authHandler.signIn(username, password) { signInError, signInValue -> - assertNull(signInError) - assertNotNull(signInValue) - accessToken = signInValue.AuthenticationResult.AccessToken - } - try { - authHandler.deleteUser(accessToken) { deleteError -> - assertNull(deleteError) - } - } catch (error: Error) { - fail(error.message) - } + ) + + assertNull(signUpResponse.exceptionOrNull()) + assertNotNull(signUpResponse.getOrNull()) + + val signInResponse = authHandler.signIn(username, password) + assertNull(signInResponse.exceptionOrNull()) + assertNotNull(signInResponse.getOrNull()) + + val deleteUserResponse = authHandler.deleteUser(signInResponse.getOrNull()!!.AuthenticationResult.AccessToken) + assertNull(deleteUserResponse.exceptionOrNull()) } @JsName("GetUserTest") @Test fun `Should get user`() = runBlocking { - var token: String = "" - createUser { t, _ -> - token = t - } - authHandler.getUser(token) { error, value -> - assertNull(error) - assertNotNull(value) - } + val (token, _) = createUser() + + val getUserAttribute = authHandler.getUser(token) + assertNull(getUserAttribute.exceptionOrNull()) + assertNotNull(getUserAttribute.getOrNull()) + deleteUser(token) } @JsName("ChangeEmailTest") @Test fun `Should change email`() = runBlocking { - var token: String = "" - createUser { t, _ -> - token = t - } - authHandler.updateUserAttributes( + val (token, _) = createUser() + + val updateUserAttributesResponse = authHandler.updateUserAttributes( token, listOf(UserAttribute(Name = "email", Value = "test2@test.test")) - ) { error, value -> - assertNull(error) - assertNotNull(value) - } - authHandler.getUser(token) { getUserError, getUserValue -> - assertNull(getUserError) - assertNotNull(getUserValue) - - getUserValue.UserAttributes.map { attribute -> - if (attribute.Name == "email") { - assertEquals("test2@test.test", attribute.Value) - } + ) + assertNull(updateUserAttributesResponse.exceptionOrNull()) + assertNotNull(updateUserAttributesResponse.getOrNull()) + + val getUserResponse = authHandler.getUser(token) + assertNull(getUserResponse.exceptionOrNull()) + assertNotNull(getUserResponse.getOrNull()) + + getUserResponse.getOrNull()!!.UserAttributes.map { attribute -> + if (attribute.Name == "email") { + assertEquals("test2@test.test", attribute.Value) } } deleteUser(token) @@ -131,160 +120,142 @@ class AuthHandlerIntegrationTests() { @JsName("ChangePasswordTest") @Test fun `Should change password`() = runBlocking { - var token: String = "" - var credential: Credential = Credential("", "") - createUser { t, c -> - token = t - credential = c - } - authHandler.changePassword(token, credential.password, credential.password + "B") { error -> - assertNull(error) - } - authHandler.signOut(token) { signOutError -> - assertNull(signOutError) - } + val (token, credentials) = createUser() + + val changePasswordResponse = authHandler.changePassword(token, credentials.password, credentials.password + "B") + assertNull(changePasswordResponse.exceptionOrNull()) + + val signOutResponse = authHandler.signOut(token) + assertNull(signOutResponse.exceptionOrNull()) + // AWS is not revoking Tokens automatically so give it some time delay(1000) - var accessToken: String = "" - authHandler.signIn(credential.username, credential.password + "B") { signInError, signInValue -> - assertNull(signInError) - assertNotNull(signInValue) - accessToken = signInValue.AuthenticationResult.AccessToken - } - deleteUser(accessToken) + + val signInResponse = authHandler.signIn(credentials.username, credentials.password + "B") + assertNull(signInResponse.exceptionOrNull()) + assertNotNull(signInResponse.getOrNull()) + + deleteUser(signInResponse.getOrNull()!!.AuthenticationResult.AccessToken) } @JsName("SignOutSignInTest") @Test fun `Sign out and sign in should succeed`() = runBlocking { - var token: String = "" - var credential: Credential = Credential("", "") - createUser { t, c -> - token = t - credential = c - } - authHandler.signOut(token) { error -> - assertNull(error) - } + val (token, credentials) = createUser() + + val signOutResponse = authHandler.signOut(token) + assertNull(signOutResponse.exceptionOrNull()) + // AWS is not revoking Tokens automatically so give it some time delay(1000) - var accessToken: String = "" - authHandler.signIn(credential.username, credential.password) { signInError, signInValue -> - assertNull(signInError) - assertNotNull(signInValue) - accessToken = signInValue.AuthenticationResult.AccessToken - } - deleteUser(accessToken) + + val signInResponse = authHandler.signIn(credentials.username, credentials.password) + assertNull(signInResponse.exceptionOrNull()) + assertNotNull(signInResponse.getOrNull()) + + deleteUser(signInResponse.getOrNull()!!.AuthenticationResult.AccessToken) } @JsName("SignUpFailPasswordTooShortTest") @Test fun `Sign up should fail because password too short`() = runBlocking { - authHandler.signUp( + val signUpResponse = authHandler.signUp( "Username", "Short", attributes = listOf( UserAttribute(Name = "email", Value = "test@test.test"), UserAttribute(Name = "custom:target_group", Value = "ROLE_USER") ) - ) { error, value -> - assertNotNull(error) - assertNull(value) - assertEquals( - "1 validation error detected: Value at 'password' failed to satisfy constraint: Member must have length greater than or equal to 6", - error.message - ) - } + ) + assertNotNull(signUpResponse.exceptionOrNull()) + assertNull(signUpResponse.getOrNull()) + assertEquals( + "1 validation error detected: Value at 'password' failed to satisfy constraint: Member must have length greater than or equal to 6", + signUpResponse.exceptionOrNull()!!.message + ) } @JsName("SignUpFailPasswordTooLongTest") @Test fun `Sign up should fail because password too long`() = runBlocking { - authHandler.signUp( + val signUpResponse = authHandler.signUp( "Username", buildString { (1..260).forEach { _ -> append("A") } }, attributes = listOf( UserAttribute(Name = "email", Value = "test@test.test"), UserAttribute(Name = "custom:target_group", Value = "ROLE_USER") ) - ) { error, value -> - assertNotNull(error) - assertNull(value) - assertEquals( - "1 validation error detected: Value at 'password' failed to satisfy constraint: Member must have length less than or equal to 256", - error.message - ) - } + ) + assertNotNull(signUpResponse.exceptionOrNull()) + assertNull(signUpResponse.getOrNull()) + assertEquals( + "1 validation error detected: Value at 'password' failed to satisfy constraint: Member must have length less than or equal to 256", + signUpResponse.exceptionOrNull()!!.message + ) } @JsName("SignUpFailUsernameTooLongTest") @Test fun `Sign up should fail because username too long`() = runBlocking { - authHandler.signUp( + var signUpResponse = authHandler.signUp( buildString { (1..130).forEach { _ -> append("A") } }, "Password", attributes = listOf( UserAttribute(Name = "email", Value = "test@test.test"), UserAttribute(Name = "custom:target_group", Value = "ROLE_USER") ) - ) { error, value -> - assertNotNull(error) - assertNull(value) - assertEquals( - "1 validation error detected: Value at 'username' failed to satisfy constraint: Member must have length less than or equal to 128", - error.message - ) - } + ) + assertNotNull(signUpResponse.exceptionOrNull()) + assertNull(signUpResponse.getOrNull()) + assertEquals( + "1 validation error detected: Value at 'username' failed to satisfy constraint: Member must have length less than or equal to 128", + signUpResponse.exceptionOrNull()!!.message + ) } @JsName("SignInTest") @Test fun `Sign in should fail because wrong credentials`() = runBlocking { - authHandler.signIn( + val signInResponse = authHandler.signIn( randomUser().username, "WRONG_PASSWORD" - ) { error, value -> - assertNotNull(error) - assertNull(value) - assertEquals("Incorrect username or password.", error.message) - } + ) + assertNotNull(signInResponse.exceptionOrNull()) + assertNull(signInResponse.getOrNull()) + assertEquals("Incorrect username or password.", signInResponse.exceptionOrNull()!!.message) } @JsName("DeleteUserFailTest") @Test fun `Get user should fail since access token wrong`() = runBlocking { - authHandler.deleteUser("WRONG_TOKEN") { error -> - assertNotNull(error) - assertEquals("Invalid Access Token", error.message) - } + val deleteUserResponse = authHandler.deleteUser("WRONG_TOKEN") + assertNotNull(deleteUserResponse.exceptionOrNull()) + assertEquals("Invalid Access Token", deleteUserResponse.exceptionOrNull()!!.message) } @JsName("DeleteUserTest") @Test fun `Delete user should fail since access token wrong`() = runBlocking { - authHandler.deleteUser("WRONG_TOKEN") { error -> - assertNotNull(error) - assertEquals("Invalid Access Token", error.message) - } + val deleteUserResponse = authHandler.deleteUser("WRONG_TOKEN") + assertNotNull(deleteUserResponse.exceptionOrNull()) + assertEquals("Invalid Access Token", deleteUserResponse.exceptionOrNull()!!.message) } @JsName("SignOutTest") @Test fun `Sign out should fail since access token wrong`() = runBlocking { - authHandler.signOut("WRONG_TOKEN") { error -> - assertNotNull(error) - assertEquals("Invalid Access Token", error.message) - } + val signOutResponse = authHandler.signOut("WRONG_TOKEN") + assertNotNull(signOutResponse.exceptionOrNull()) + assertEquals("Invalid Access Token", signOutResponse.exceptionOrNull()!!.message) } @JsName("UpdateUserAttributesTest") @Test fun `Update attributes should fail since access token wrong`() = runBlocking { - authHandler.updateUserAttributes( + val updateUserAttributesResponse = authHandler.updateUserAttributes( "WRONG_TOKEN", attributes = listOf( UserAttribute(Name = "email", Value = "test@test.test") ) - ) { error, value -> - assertNotNull(error) - assertNull(value) - assertEquals("Invalid Access Token", error.message) - } + ) + assertNotNull(updateUserAttributesResponse.exceptionOrNull()) + assertNull(updateUserAttributesResponse.getOrNull()) + assertEquals("Invalid Access Token", updateUserAttributesResponse.exceptionOrNull()!!.message) } } diff --git a/auth/src/iosMain/kotlin/com/liftric/base/Environment.kt b/auth/src/iosMain/kotlin/com/liftric/base/Environment.kt index a69d72f..f0b0d1d 100644 --- a/auth/src/iosMain/kotlin/com/liftric/base/Environment.kt +++ b/auth/src/iosMain/kotlin/com/liftric/base/Environment.kt @@ -2,7 +2,7 @@ package com.liftric.base import platform.Foundation.NSProcessInfo -actual class Environment actual constructor() { +actual internal class Environment actual constructor() { actual companion object { actual fun variable(value: String): String? { return NSProcessInfo().environment[value].toString() diff --git a/gradle.properties b/gradle.properties index a5c74fc..5655915 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,3 +4,7 @@ org.gradle.jvmargs=-Xmx4096m kotlin.native.enableDependencyPropagation=false kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.mpp.enableCompatibilityMetadataVariant=true +kotlin.incremental=true +kotlin.incremental.multiplatform=true +kotlin.caching.enabled=true +kotlin.parallel.tasks.in.project=true