Skip to content

Commit

Permalink
Dynamo add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Oct 9, 2023
1 parent 605208e commit 33a7cdc
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion demo/src/main/kotlin/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ object Server : ServerPathGroup(ServerPath.root) {
val proofEmail = EmailProofEndpoints(path("proof/email"), pins, email, { to, pin ->
Email(
subject = "Log In Code",
to = listOf(),
to = listOf(EmailLabeledValue(to)),
plainText = "Your PIN is $pin."
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,11 @@ class DynamoDbCache(val makeClient: () -> DynamoDbAsyncClient, val tableName: St
client.updateItem {
it.tableName(tableName)
it.key(mapOf("key" to AttributeValue.fromS(key)))
it.updateExpression("SET #exp = :exp, #v = #v + :v")
it.updateExpression("SET #exp = :exp, #v = if_not_exists(#v, :z) + :v")
it.expressionAttributeNames(mapOf("#v" to "value", "#exp" to "expiration"))
it.expressionAttributeValues(
mapOf(
":z" to AttributeValue.fromN("0"),
":v" to AttributeValue.fromN(value.toString()),
":exp" to (timeToLive?.let { AttributeValue.fromN(now().plus(it).epochSeconds.toString()) }
?: AttributeValue.fromNul(true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ abstract class CacheTest {
cache.remove(key)
assertTrue(cache.modify<Int>(key) { it?.plus(1) ?: 0 })
assertEquals(0, cache.get<Int>(key))

cache.remove(key)
cache.add(key, 1)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.lightningkite.lightningserver

import com.lightningkite.lightningdb.collection
import com.lightningkite.lightningdb.test.User
import com.lightningkite.lightningserver.auth.JwtSigner
import com.lightningkite.lightningserver.auth.authOptions
import com.lightningkite.lightningserver.auth.oauth.OauthProviderCredentials
import com.lightningkite.lightningserver.auth.oauth.OauthProviderCredentialsApple
Expand Down Expand Up @@ -33,6 +34,7 @@ object TestSettings {
val sms = setting("sms", SMSSettings("test"))
val cache = setting("cache", CacheSettings())
val files = setting("files", FilesSettings())
val jwtSigner = setting("jwtSigner", JwtSigner())
val oauthGoogle = setting<OauthProviderCredentials?>("oauth_google", null)
val oauthApple = setting<OauthProviderCredentialsApple?>("oauth_apple", null)
val oauthGithub = setting<OauthProviderCredentials?>("oauth_github", null)
Expand All @@ -47,7 +49,7 @@ object TestSettings {
)
val emailAccess: UserEmailAccess<User, UUID> = info.userEmailAccess { User(email = it, phoneNumber = it) }
val path = ServerPath("auth")
val baseAuth = BaseAuthEndpoints(path, emailAccess, 1.hours, 5.minutes)
val baseAuth = BaseAuthEndpoints(path, emailAccess, jwtSigner, 1.hours, 5.minutes)
val emailAuth = EmailAuthEndpoints(baseAuth, emailAccess, cache, email)

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SmsAuthTest {
)
val phoneAccess: UserPhoneAccess<User, UUID> = info.userPhoneAccess { User(email = "$it@phone", phoneNumber = it) }
val path = ServerPath("auth")
val baseAuth = BaseAuthEndpoints(path, phoneAccess, expiration = 1.hours, emailExpiration = 5.minutes)
val baseAuth = BaseAuthEndpoints(path, phoneAccess, TestSettings.jwtSigner, expiration = 1.hours, emailExpiration = 5.minutes)
val phoneAuth = SmsAuthEndpoints(baseAuth, phoneAccess, TestSettings.cache, TestSettings.sms)
runBlocking {
phoneAuth.loginSms.implementation(AuthAndPathParts(null, null, arrayOf()), "8013693729")
Expand All @@ -65,7 +65,7 @@ class SmsAuthTest {
)
val phoneAccess: UserPhoneAccess<User, UUID> = info.userPhoneAccess { User(email = "$it@phone", phoneNumber = it) }
val path = ServerPath("auth")
val baseAuth = BaseAuthEndpoints(path, phoneAccess, expiration = 1.hours, emailExpiration = 5.minutes)
val baseAuth = BaseAuthEndpoints(path, phoneAccess, TestSettings.jwtSigner, expiration = 1.hours, emailExpiration = 5.minutes)
val phoneAuth = SmsAuthEndpoints(baseAuth, phoneAccess, TestSettings.cache, TestSettings.sms)
runBlocking {
phoneAuth.loginSms.implementation(AuthAndPathParts(null, null, arrayOf()), "8013693729")
Expand Down
2 changes: 1 addition & 1 deletion shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ kotlin {
js(IR) {
browser()
}
// ios()
ios()
// androidTarget()

sourceSets {
Expand Down

0 comments on commit 33a7cdc

Please sign in to comment.