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’m 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’ve tried using curl

curl -X POST “http://localhost:8080/api/v1/phrases” -H “Accept: application/json” -H “Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBdXRoZW50aWNhdGlvbiIsImlzcyI6ImVtb2ppcGhyYXNlcyIsImlkIjoibGFucmUiLCJleHAiOjE1NjM2MjU4Nzl9.HynWY9Mmlo8OvS44CSbuYOu0_nE_xcD_cakY-T0S4sugAXN61y0aw2-TM6ML1shRvlU-cECqRgY6h85_jgSVsg”

and that doesn’t 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’re 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…probably some dirty data.

thanks

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

@shogunkaramazov I’m not sure you’re 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! :]