Skip to content

Commit

Permalink
refactor authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
stslex committed Aug 29, 2023
1 parent 4dc9526 commit 503f8d8
Show file tree
Hide file tree
Showing 28 changed files with 677 additions and 106 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 123 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.stslex.aproselection.controller

import com.stslex.aproselection.core.datastore.AppDataStore
import com.stslex.aproselection.core.network.client.NetworkClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -12,7 +11,6 @@ import kotlin.coroutines.coroutineContext

class AuthControllerImpl(
private val dataStore: AppDataStore,
private val networkClient: NetworkClient,
) : AuthController {

private val _isAuth = MutableStateFlow<Boolean?>(null)
Expand All @@ -22,15 +20,7 @@ class AuthControllerImpl(
override suspend fun init() {
dataStore.token
.onEach { token ->
if (token.isBlank()) {
networkClient.regenerateToken()
}
}
.launchIn(CoroutineScope(coroutineContext))

dataStore.uuid
.onEach { uuid ->
_isAuth.emit(uuid.isNotBlank())
_isAuth.emit(token.isNotBlank())
}
.launchIn(CoroutineScope(coroutineContext))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import kotlinx.coroutines.flow.StateFlow

interface AppDataStore {

val uuid: StateFlow<String>
val token: StateFlow<String>

suspend fun setUuid(uuid: String)
val credential: StateFlow<UserCredential>

suspend fun setToken(token: String)

suspend fun setCredential(credential: UserCredential)

suspend fun clear()

suspend fun init()
Expand Down
Loading

0 comments on commit 503f8d8

Please sign in to comment.