-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
android/app/src/main/java/by/eapp/musicroom/di/AuthModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package by.eapp.musicroom.di | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler | ||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.emptyPreferences | ||
import androidx.datastore.preferences.preferencesDataStoreFile | ||
import by.eapp.musicroom.data.login.storage.JwtTokenStorage | ||
import by.eapp.musicroom.domain.repo.login.JwtTokenManager | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object AuthModule { | ||
@Provides | ||
@Singleton | ||
fun provideDataStore( | ||
@ApplicationContext appContext: Context, | ||
): DataStore<Preferences> { | ||
return PreferenceDataStoreFactory.create( | ||
corruptionHandler = ReplaceFileCorruptionHandler( | ||
produceNewData = { emptyPreferences() } | ||
), | ||
produceFile = { appContext.preferencesDataStoreFile("auth_datastore") } | ||
) | ||
} | ||
|
||
|
||
@Provides | ||
@Singleton | ||
fun provideJwtTokenManager(dataStore: DataStore<Preferences>): | ||
JwtTokenManager = JwtTokenStorage(dataStore) | ||
|
||
} |