Skip to content

Commit aafc3dd

Browse files
committed
fix: pass session token to refresh method
1 parent 0798731 commit aafc3dd

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/main/kotlin/com/ctrlhub/core/auth/AuthRouter.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import io.ktor.client.call.*
1313
import io.ktor.client.plugins.*
1414
import io.ktor.client.request.delete
1515
import io.ktor.client.request.get
16+
import io.ktor.client.request.header
1617
import io.ktor.client.request.post
1718
import io.ktor.client.request.setBody
1819
import io.ktor.http.*
@@ -30,9 +31,13 @@ class AuthRouter(httpClient: HttpClient) : Router(httpClient = httpClient) {
3031
}
3132
}
3233

33-
suspend fun refresh(): AuthFlowResponse {
34+
suspend fun refresh(sessionToken: String): AuthFlowResponse {
3435
return try {
35-
httpClient.get("${Config.authBaseUrl}/self-service/login/api?refresh=true").body()
36+
httpClient.get("${Config.authBaseUrl}/self-service/login/api?refresh=true") {
37+
headers {
38+
header("X-Session-Token", sessionToken)
39+
}
40+
}.body()
3641
} catch (e: ClientRequestException) {
3742
throw ApiClientException("Failed to initiate auth", e.response, e)
3843
} catch (e: Exception) {

src/test/kotlin/com/ctrlhub/core/auth/AuthRouterTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class AuthRouterTest {
105105

106106
runBlocking {
107107
assertFailsWith<ApiException> {
108-
authRouter.refresh()
108+
authRouter.refresh("sess-123")
109109
}
110110
}
111111
}
@@ -123,7 +123,7 @@ class AuthRouterTest {
123123
val authRouter = AuthRouter(httpClient = HttpClient(mockEngine).configureForTest())
124124

125125
runBlocking {
126-
val response = authRouter.refresh()
126+
val response = authRouter.refresh("sess-123")
127127
assertEquals("test-123", response.id)
128128
}
129129
}

0 commit comments

Comments
 (0)