I don’t know how to call or use dataStore other than in the viewmodel
I want to use the token value from the data store, to save the value it works, but when I call the datastore to the MainRemote.kt file a problem occurs, I only know how to use it in the viewmodel
this code in my MainRemote.kt
class MainRemote() {
var authDataStorePreferences = ConnectionReleaseApplication().authDataStorePreferences
init {
}
val client = HttpClient(CIO) {
defaultRequest {
url(host = BuildConfig.apiDomain, port = 3000)
contentType(ContentType.Application.Json)
}
install(Auth){
bearer {
loadTokens {
BearerTokens("token","mklklkl")
}
}
}
install(ContentNegotiation) {
json(
Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
}
)
install(Logging) {
logger = Logger.ANDROID
level = LogLevel.BODY
}
}
}
}
this code when i register datastore in file ConnectionReleaseApp.kt
private const val AUTH_PREFERENCES_NAME = "auth_preferances_name"
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = AUTH_PREFERENCES_NAME)
class ConnectionReleaseApplication : Application() {
lateinit var authDataStorePreferences: AuthDataStorePreferences
override fun onCreate() {
super.onCreate()
authDataStorePreferences = AuthDataStorePreferences(dataStore)
}
}
New contributor
299 M Razak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.