Store base url too
This commit is contained in:
@@ -24,7 +24,7 @@ class AuthRepoImpl @Inject constructor(
|
|||||||
Timber.d("authenticate result is $authResult")
|
Timber.d("authenticate result is $authResult")
|
||||||
if (authResult.isFailure) return authResult.exceptionOrNull()
|
if (authResult.isFailure) return authResult.exceptionOrNull()
|
||||||
val token = checkNotNull(authResult.getOrNull())
|
val token = checkNotNull(authResult.getOrNull())
|
||||||
storage.storeToken(token)
|
storage.storeAuthData(token, baseUrl)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,5 @@ package gq.kirmanak.mealie.data.auth
|
|||||||
|
|
||||||
interface AuthStorage {
|
interface AuthStorage {
|
||||||
suspend fun isAuthenticated(): Boolean
|
suspend fun isAuthenticated(): Boolean
|
||||||
suspend fun storeToken(token: String)
|
suspend fun storeAuthData(token: String, baseUrl: String)
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ import timber.log.Timber
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val TOKEN_KEY = "AUTH_TOKEN"
|
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 {
|
class AuthStorageImpl @Inject constructor(@ApplicationContext private val context: Context) : AuthStorage {
|
||||||
private val sharedPreferences: SharedPreferences
|
private val sharedPreferences: SharedPreferences
|
||||||
@@ -22,8 +23,11 @@ class AuthStorageImpl @Inject constructor(@ApplicationContext private val contex
|
|||||||
token != null
|
token != null
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun storeToken(token: String) {
|
override suspend fun storeAuthData(token: String, baseUrl: String) {
|
||||||
Timber.d("storeToken() called with: token = $token")
|
Timber.v("storeAuthData() called with: token = $token, baseUrl = $baseUrl")
|
||||||
sharedPreferences.edit().putString(TOKEN_KEY, token).apply()
|
sharedPreferences.edit()
|
||||||
|
.putString(TOKEN_KEY, token)
|
||||||
|
.putString(BASE_URL_KEY, baseUrl)
|
||||||
|
.apply()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user