update dependencies
This commit is contained in:
build.gradlegradle.properties
client
defaultAndroidSettings.gradlefeatures
auth
client
src
commonMain
kotlin
dev
inmo
postssystem
features
auth
client
common
src
commonMain
kotlin
dev
inmo
postssystem
features
auth
common
common
users
server
gradle
39
features/auth/common/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/common/AuthModels.kt
39
features/auth/common/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/common/AuthModels.kt
@ -3,10 +3,49 @@ package dev.inmo.postssystem.features.auth.common
|
||||
import com.benasher44.uuid.uuid4
|
||||
import dev.inmo.postssystem.features.users.common.Username
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlin.jvm.JvmInline
|
||||
|
||||
@Serializable(AuthKeySerializer::class)
|
||||
sealed interface AuthKey
|
||||
|
||||
@Serializable
|
||||
private data class AuthKeySurrogate(
|
||||
val authCreds: AuthCreds?,
|
||||
val token: AuthToken?,
|
||||
val refreshToken: RefreshToken?
|
||||
)
|
||||
|
||||
@Serializer(AuthKey::class)
|
||||
object AuthKeySerializer : KSerializer<AuthKey> {
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = AuthKeySurrogate.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): AuthKey {
|
||||
val surrogate = AuthKeySurrogate.serializer().deserialize(decoder)
|
||||
when {
|
||||
surrogate.authCreds != null -> return surrogate.authCreds
|
||||
surrogate.token != null -> return surrogate.token
|
||||
surrogate.refreshToken != null -> return surrogate.refreshToken
|
||||
}
|
||||
error("Unsupported version of auth key surrogate")
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: AuthKey) {
|
||||
AuthKeySurrogate.serializer().serialize(
|
||||
encoder,
|
||||
AuthKeySurrogate(
|
||||
value as? AuthCreds,
|
||||
value as? AuthToken,
|
||||
value as? RefreshToken
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@SerialName("authcreds")
|
||||
data class AuthCreds(
|
||||
|
Reference in New Issue
Block a user