-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
👍 セッションのリフレッシュ処理を追加 #103
Merged
Merged
👍 セッションのリフレッシュ処理を追加 #103
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
プロパティの名前が誤解を招く可能性があります。
observeAuthStatusUseCase
はAuthStatusStreamUseCase
のインスタンスを参照しているため、名前をauthStatusStreamUseCase
に変更することを検討してください。Committable suggestion