Skip to content

Commit 9ec0e4d

Browse files
fix: change receive method in auth api
1 parent 0376518 commit 9ec0e4d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/main/kotlin/infrastructure/api/routes/AuthenticationAPI.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
package infrastructure.api.routes
1010

1111
import application.controller.UserController
12+
import entity.user.User
1213
import infrastructure.provider.Provider
1314
import io.ktor.http.HttpStatusCode
1415
import io.ktor.server.application.call
16+
import io.ktor.server.request.receive
17+
import io.ktor.server.request.receiveText
1518
import io.ktor.server.response.respond
1619
import io.ktor.server.routing.Route
1720
import io.ktor.server.routing.post
@@ -22,15 +25,18 @@ import usecase.AuthenticationUseCase
2225
*/
2326
fun Route.authAPI(provider: Provider, apiPath: String) {
2427
post("$apiPath/auth") {
25-
if (AuthenticationUseCase(
26-
call.parameters["userId"].toString(),
27-
call.parameters["password"].toString(),
28-
UserController(provider.userDatabaseManager),
29-
).execute()
30-
) {
31-
call.respond(HttpStatusCode.OK)
32-
} else {
33-
call.respond(HttpStatusCode.Unauthorized, "Error: wrong credentials!")
28+
call.receive<User>().run {
29+
if (AuthenticationUseCase(
30+
this.userId,
31+
this.password,
32+
UserController(provider.userDatabaseManager),
33+
).execute()
34+
) {
35+
call.respond(HttpStatusCode.OK)
36+
} else {
37+
call.respond(HttpStatusCode.Unauthorized, "Error: wrong credentials!")
38+
}
3439
}
40+
3541
}
3642
}

0 commit comments

Comments
 (0)