-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Implement token storage mechanism and add network request for t…
…oken renewal on expiration
- Loading branch information
Showing
33 changed files
with
315 additions
and
57 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
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
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 |
---|---|---|
|
@@ -8,4 +8,5 @@ android { | |
} | ||
|
||
dependencies { | ||
implementation(libs.kotlinx.coroutines.android) | ||
} |
51 changes: 51 additions & 0 deletions
51
core/common/src/main/java/store/newsbriefing/app/core/common/util/BriefingLogger.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,51 @@ | ||
package store.newsbriefing.app.core.common.util | ||
|
||
import android.util.Log | ||
import store.newsbriefing.app.core.common.BuildConfig | ||
|
||
object BriefingLogger { | ||
|
||
private fun getClassName(): String { | ||
val ste = Thread.currentThread().stackTrace | ||
for (i in ste.indices) { | ||
if (ste[i].fileName != "BriefingLogger.kt") { | ||
return ste[i].fileName.replace(".kt", "") | ||
} | ||
} | ||
return "UnknownClass" | ||
} | ||
|
||
fun e(message: String?, TAG: String = getClassName()) { | ||
if (isDebugMode()) Log.e(TAG, buildLogMsg(message)) | ||
} | ||
|
||
fun w(message: String?, TAG: String = getClassName()) { | ||
if (isDebugMode()) Log.w(TAG, buildLogMsg(message)) | ||
} | ||
|
||
fun i(message: String?, TAG: String = getClassName()) { | ||
if (isDebugMode()) Log.i(TAG, buildLogMsg(message)) | ||
} | ||
|
||
fun d(message: String?, TAG: String = getClassName()) { | ||
if (isDebugMode()) Log.d(TAG, buildLogMsg(message)) | ||
} | ||
|
||
fun v(message: String?, TAG: String = getClassName()) { | ||
if (isDebugMode()) Log.v(TAG, buildLogMsg(message)) | ||
} | ||
|
||
private fun isDebugMode(): Boolean = BuildConfig.DEBUG | ||
|
||
private fun buildLogMsg(message: String?): String { | ||
val ste = Thread.currentThread().stackTrace[4] | ||
return buildString { | ||
append("[") | ||
append(ste.fileName.replace(".kt", "")) | ||
append("::") | ||
append(ste.methodName) | ||
append("] ") | ||
message?.let { append(it) } | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
5 changes: 5 additions & 0 deletions
5
core/datastore/src/main/java/store/newsbriefing/app/core/datastore/DataStoreConstant.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,5 @@ | ||
package store.newsbriefing.app.core.datastore | ||
|
||
object DataStoreConstant { | ||
const val DBNAME = "briefing_datastore.preferences_pb" | ||
} |
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
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
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
27 changes: 27 additions & 0 deletions
27
core/datastore/src/main/java/store/newsbriefing/app/core/datastore/di/DataStoreModule.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,27 @@ | ||
package store.newsbriefing.app.core.datastore.di | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.dataStoreFile | ||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory | ||
import androidx.datastore.preferences.core.Preferences | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import store.newsbriefing.app.core.datastore.DataStoreConstant | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object DataStoreModule { | ||
|
||
@Provides | ||
@Singleton | ||
internal fun providesDataStore(@ApplicationContext context: Context): DataStore<Preferences> { | ||
return PreferenceDataStoreFactory.create(produceFile = { context.dataStoreFile( | ||
DataStoreConstant.DBNAME | ||
) }) | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
...ain/src/main/kotlin/store/newsbriefing/app/core/domain/SignInWithSocialProviderUseCase.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,19 @@ | ||
package store.newsbriefing.app.core.domain | ||
|
||
import kotlinx.coroutines.flow.first | ||
import store.newsbriefing.app.core.common.util.BriefingLogger | ||
import store.newsbriefing.app.core.data.repository.MemberRepository | ||
import store.newsbriefing.app.core.data.repository.MemberTokenRepository | ||
import store.newsbriefing.app.core.model.SocialProvider | ||
import javax.inject.Inject | ||
|
||
class SignInWithSocialProviderUseCase @Inject constructor( | ||
private val memberRepository: MemberRepository, | ||
private val memberTokenRepository: MemberTokenRepository | ||
) { | ||
suspend operator fun invoke(provider : SocialProvider, identityToken : String) { | ||
val memberToken = memberRepository.getTokenWithSocialProvider(provider, identityToken).first() | ||
memberTokenRepository.saveMemberToken(memberToken.memberId, memberToken.accessToken, memberToken.refreshToken) | ||
BriefingLogger.i("signed in member Id : ${memberToken.memberId}") | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
core/model/src/main/java/store/newsbriefing/app/core/model/SocialProvider.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,5 @@ | ||
package store.newsbriefing.app.core.model | ||
|
||
enum class SocialProvider(val value: String) { | ||
GOOGLE("google") | ||
} |
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
3 changes: 2 additions & 1 deletion
3
...k/src/main/java/store/newsbriefing/app/core/network/datasource/MemberNetworkDataSource.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
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
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
Oops, something went wrong.