fix: Login endpoint uses form-urlencoded not body
This commit is contained in:
parent
328c51bc82
commit
7f4de4cb30
|
@ -1,10 +1,5 @@
|
|||
package com.p_vacho.neat_calendar.api.models
|
||||
|
||||
data class LoginRequest(
|
||||
val username: String,
|
||||
val password: String,
|
||||
)
|
||||
|
||||
data class LoginResponse(
|
||||
val access_token: String,
|
||||
val expires_in: Int,
|
||||
|
|
|
@ -3,13 +3,16 @@ package com.p_vacho.neat_calendar.api.services
|
|||
import com.p_vacho.neat_calendar.api.models.*
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.Field
|
||||
import retrofit2.http.FormUrlEncoded
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.POST
|
||||
|
||||
interface AuthService {
|
||||
@FormUrlEncoded
|
||||
@POST("auth/login")
|
||||
suspend fun login(@Body loginRequest: LoginRequest): LoginResponse
|
||||
suspend fun login(@Field("username") username: String, @Field("password") password: String): LoginResponse
|
||||
|
||||
@POST("auth/refresh")
|
||||
suspend fun refreshToken(@Header("Authorization") refreshToken: String): RefreshResponse
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.p_vacho.neat_calendar.auth
|
|||
|
||||
import android.util.Log
|
||||
import com.p_vacho.neat_calendar.api.RetrofitClient
|
||||
import com.p_vacho.neat_calendar.api.models.LoginRequest
|
||||
import com.p_vacho.neat_calendar.api.models.RegisterRequest
|
||||
import com.p_vacho.neat_calendar.api.models.RegisterResponse
|
||||
import com.p_vacho.neat_calendar.api.models.SessionResponse
|
||||
|
@ -15,7 +14,7 @@ class AuthRepository(private val tokenManager: TokenManager) {
|
|||
suspend fun login(username: String, password: String): Boolean {
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val response = RetrofitClient.authService.login(LoginRequest(username, password))
|
||||
val response = RetrofitClient.authService.login(username, password)
|
||||
tokenManager.storeAccessToken(response.access_token, response.expires_in)
|
||||
tokenManager.storeRefreshToken(response.refresh_token, response.refresh_token_expires_in)
|
||||
Log.i("API", "Login successful")
|
||||
|
|
Loading…
Reference in a new issue