-
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.
Merge pull request #103 from 2rabs/rt/add-session-refresh
👍 セッションのリフレッシュ処理を追加
- Loading branch information
Showing
28 changed files
with
229 additions
and
159 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
27 changes: 27 additions & 0 deletions
27
app/ios/Modules/Sources/KmpContainer/AuthStatusStreamUseCaseProvider.swift
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 @@ | ||
import Dependencies | ||
import NitoKmp | ||
|
||
public struct AuthStatusStreamUseCaseProvider { | ||
private static var observeAuthStatusUseCase: AuthStatusStreamUseCase { | ||
Container.shared.get(type: AuthStatusStreamUseCase.self) | ||
} | ||
|
||
public let execute: () -> AsyncThrowingStream<AuthStatus, Error> | ||
} | ||
|
||
extension AuthStatusStreamUseCaseProvider: DependencyKey { | ||
@MainActor | ||
static public var liveValue: AuthStatusStreamUseCaseProvider = | ||
AuthStatusStreamUseCaseProvider( | ||
execute: { | ||
observeAuthStatusUseCase.invoke().stream() | ||
} | ||
) | ||
} | ||
|
||
extension DependencyValues { | ||
public var authStatusStreamUseCase: AuthStatusStreamUseCaseProvider { | ||
get { self[AuthStatusStreamUseCaseProvider.self] } | ||
set { self[AuthStatusStreamUseCaseProvider.self] = newValue } | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
app/ios/Modules/Sources/KmpContainer/ObserveAuthStatusUseCaseProvider.swift
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,8 @@ private fun RouteBuilder.root( | |
), | ||
), | ||
) | ||
|
||
else -> {} | ||
} | ||
} | ||
} |
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
3 changes: 1 addition & 2 deletions
3
core/data/src/commonMain/kotlin/club/nito/core/data/DefaultAuthRepository.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
18 changes: 18 additions & 0 deletions
18
core/domain/src/commonMain/kotlin/club/nito/core/domain/AuthStatusStreamUseCase.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,18 @@ | ||
package club.nito.core.domain | ||
|
||
import club.nito.core.data.AuthRepository | ||
import club.nito.core.model.AuthStatus | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
/** | ||
* 認証状態を購読するユースケース | ||
*/ | ||
public sealed interface AuthStatusStreamUseCase { | ||
public operator fun invoke(): Flow<AuthStatus> | ||
} | ||
|
||
public class AuthStatusStreamExecutor( | ||
private val authRepository: AuthRepository, | ||
) : AuthStatusStreamUseCase { | ||
override fun invoke(): Flow<AuthStatus> = authRepository.authStatus | ||
} |
19 changes: 0 additions & 19 deletions
19
core/domain/src/commonMain/kotlin/club/nito/core/domain/ObserveAuthStatusUseCase.kt
This file was deleted.
Oops, something went wrong.
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
4 changes: 4 additions & 0 deletions
4
core/model/src/commonMain/kotlin/club/nito/core/model/AuthState.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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package club.nito.core.model | ||
|
||
public sealed interface AuthStatus { | ||
public data object Loading : AuthStatus | ||
|
||
public data object NotAuthenticated : AuthStatus | ||
|
||
public data class Authenticated(val session: UserSession) : AuthStatus | ||
|
||
public data object NetworkError : AuthStatus | ||
} |
38 changes: 38 additions & 0 deletions
38
core/network/src/commonMain/kotlin/club/nito/core/network/NetworkService.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,38 @@ | ||
package club.nito.core.network | ||
|
||
import club.nito.core.model.ApiException | ||
import club.nito.core.model.NitoError | ||
import club.nito.core.network.auth.AuthRemoteDataSource | ||
import io.ktor.client.network.sockets.SocketTimeoutException | ||
import io.ktor.client.plugins.HttpRequestTimeoutException | ||
import io.ktor.client.plugins.ResponseException | ||
import io.ktor.util.cio.ChannelReadException | ||
import kotlinx.coroutines.TimeoutCancellationException | ||
|
||
public class NetworkService( | ||
public val authRemoteDataSource: AuthRemoteDataSource, | ||
) { | ||
public suspend inline operator fun <reified T : Any> invoke( | ||
block: () -> T, | ||
): T = try { | ||
authRemoteDataSource.authIfNeeded() | ||
block() | ||
} catch (e: Throwable) { | ||
throw e.toNitoError() | ||
} | ||
} | ||
|
||
public fun Throwable.toNitoError(): NitoError = when (this) { | ||
is NitoError -> this | ||
|
||
is ResponseException -> ApiException.ServerException(this) | ||
|
||
is ChannelReadException -> ApiException.NetworkException(this) | ||
|
||
is TimeoutCancellationException, | ||
is HttpRequestTimeoutException, | ||
is SocketTimeoutException, | ||
-> ApiException.TimeoutException(this) | ||
|
||
else -> ApiException.UnknownException(this) | ||
} |
4 changes: 2 additions & 2 deletions
4
core/network/src/commonMain/kotlin/club/nito/core/network/auth/AuthRemoteDataSource.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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package club.nito.core.network.auth | ||
|
||
import club.nito.core.model.AuthStatus | ||
import club.nito.core.model.FetchSingleResult | ||
import club.nito.core.model.UserInfo | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
public sealed interface AuthRemoteDataSource { | ||
public val authStatus: Flow<FetchSingleResult<AuthStatus>> | ||
public val authStatus: Flow<AuthStatus> | ||
|
||
public suspend fun login(email: String, password: String) | ||
public suspend fun logout() | ||
public suspend fun modifyAuthUser(email: String?, password: String?): UserInfo | ||
public suspend fun authIfNeeded() | ||
} |
Oops, something went wrong.