Store base url too

This commit is contained in:
Kirill Kamakin
2021-11-07 18:29:37 +03:00
parent ae74dac851
commit f5ee40d945
3 changed files with 9 additions and 5 deletions

View File

@@ -24,7 +24,7 @@ class AuthRepoImpl @Inject constructor(
Timber.d("authenticate result is $authResult")
if (authResult.isFailure) return authResult.exceptionOrNull()
val token = checkNotNull(authResult.getOrNull())
storage.storeToken(token)
storage.storeAuthData(token, baseUrl)
return null
}
}

View File

@@ -2,5 +2,5 @@ package gq.kirmanak.mealie.data.auth
interface AuthStorage {
suspend fun isAuthenticated(): Boolean
suspend fun storeToken(token: String)
suspend fun storeAuthData(token: String, baseUrl: String)
}

View File

@@ -10,6 +10,7 @@ import timber.log.Timber
import javax.inject.Inject
private const val TOKEN_KEY = "AUTH_TOKEN"
private const val BASE_URL_KEY = "BASE_URL"
class AuthStorageImpl @Inject constructor(@ApplicationContext private val context: Context) : AuthStorage {
private val sharedPreferences: SharedPreferences
@@ -22,8 +23,11 @@ class AuthStorageImpl @Inject constructor(@ApplicationContext private val contex
token != null
}
override suspend fun storeToken(token: String) {
Timber.d("storeToken() called with: token = $token")
sharedPreferences.edit().putString(TOKEN_KEY, token).apply()
override suspend fun storeAuthData(token: String, baseUrl: String) {
Timber.v("storeAuthData() called with: token = $token, baseUrl = $baseUrl")
sharedPreferences.edit()
.putString(TOKEN_KEY, token)
.putString(BASE_URL_KEY, baseUrl)
.apply()
}
}