Server-Side Kotlin with Ktor 路 Get Phrases API | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2885892-server-side-kotlin-with-ktor/lessons/27

Hi Ray, I鈥檓 getting this error when trying to execute api/v1/phrases

2019-07-19 13:40:07.773 [nioEventLoopGroup-4-2] TRACE io.ktor.auth.jwt - JWT verification failed: No transaction in context.
2019-07-19 13:40:07.775 [nioEventLoopGroup-4-2] TRACE io.ktor.auth.Authentication - Responding unauthorized because of error No transaction in context.

I鈥檝e tried using curl

curl -X POST 鈥http://localhost:8080/api/v1/phrases鈥 -H 鈥淎ccept: application/json鈥 -H 鈥淎uthorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBdXRoZW50aWNhdGlvbiIsImlzcyI6ImVtb2ppcGhyYXNlcyIsImlkIjoibGFucmUiLCJleHAiOjE1NjM2MjU4Nzl9.HynWY9Mmlo8OvS44CSbuYOu0_nE_xcD_cakY-T0S4sugAXN61y0aw2-TM6ML1shRvlU-cECqRgY6h85_jgSVsg鈥

and that doesn鈥檛 work either. Please do you have any pointers?

Hi @arkangelx thanks for the question! My first thoughts would be to (1) make sure you have your environment variables such as JWT_SECRET set up correctly, as mentioned in the previous video, (2) make sure you鈥檙e using the same JWT token that you received from calling the login endpoint, and (3) make sure there are phrases in the database. None of these fit that error exactly, but they may point you in the direction of how to diagnose the error. Thanks again!

Hi Ray, I found a problem in the userById query鈥robably some dirty data.

thanks

@macsimus Can you please help with this when you get a chance? Thank you - much appreciated! :]

@shogunkaramazov I鈥檓 not sure you鈥檙e having the same trouble, but I got the same error as above at the beginning, until I realized that I had override suspend fun getUserById(userId: String) : User? {...} when it should have been override suspend fun getUserById(userId: String) = dbQuery {...}

@noloman Thank you for sharing the solution - much appreciated! :]