Skip to content

Commit 2edbe7d

Browse files
committed
🐛 fix apple signin error alert
1 parent 10db64f commit 2edbe7d

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

composeApp/src/commonMain/kotlin/com/slax/reader/ui/login/LoginScreen.kt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,13 @@ fun LoginScreen(navController: NavHostController) {
8989
}
9090

9191
Column(
92-
modifier = Modifier.fillMaxSize().background(Color.White).windowInsetsPadding(WindowInsets.navigationBars),
93-
verticalArrangement = Arrangement.SpaceBetween
92+
modifier = Modifier.fillMaxSize().background(Color.White).windowInsetsPadding(WindowInsets.navigationBars)
9493
) {
9594
// 顶部内容区域
96-
Column {
97-
Spacer(
98-
modifier = Modifier
99-
.fillMaxWidth()
100-
.aspectRatio(375f / 128f)
101-
)
95+
Column(
96+
modifier = Modifier.weight(1f, fill = false)
97+
) {
98+
Spacer(modifier = Modifier.heightIn(min = 48.dp, max = 128.dp).fillMaxWidth().weight(0.15f))
10299

103100
Text(
104101
text = "欢迎来到 \nSlax Reader",
@@ -134,9 +131,15 @@ fun LoginScreen(navController: NavHostController) {
134131
}
135132
}
136133

134+
Spacer(modifier = Modifier.height(16.dp))
135+
137136
// 底部登录按钮区域
138137
Column(modifier = Modifier.padding(bottom = 30.dp)) {
139138
GoogleButtonUiContainer(onGoogleSignInResult = { googleUser ->
139+
if (googleUser == null) {
140+
return@GoogleButtonUiContainer
141+
}
142+
140143
scope.launch {
141144
viewModel.googleSignIn(
142145
googleUser,
@@ -176,6 +179,13 @@ fun LoginScreen(navController: NavHostController) {
176179
pendingLoginAction = {
177180
scope.launch {
178181
val result = appleProvider.signIn()
182+
if (result.isFailure) {
183+
val error = result.exceptionOrNull()
184+
if (!error?.message.orEmpty().contains("canceled", ignoreCase = true)) {
185+
errorMessage = error?.message
186+
}
187+
return@launch
188+
}
179189
viewModel.appleSignIn(
180190
result = result,
181191
onSuccess = successHandle,
@@ -188,6 +198,13 @@ fun LoginScreen(navController: NavHostController) {
188198
} else {
189199
scope.launch {
190200
val result = appleProvider.signIn()
201+
if (result.isFailure) {
202+
val error = result.exceptionOrNull()
203+
if (!error?.message.orEmpty().contains("canceled", ignoreCase = true)) {
204+
errorMessage = error?.message
205+
}
206+
return@launch
207+
}
191208
viewModel.appleSignIn(
192209
result = result,
193210
onSuccess = successHandle,

composeApp/src/commonMain/kotlin/com/slax/reader/ui/login/ViewModel.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ class LoginViewModel(
6464
onSuccess: () -> Unit,
6565
onError: (err: String) -> Unit
6666
) {
67-
if (result == null || result.idToken == "") {
67+
if (result == null) {
68+
return
69+
}
70+
71+
if (result.idToken == "") {
6872
onError("Failed to get Google ID token")
6973
return
7074
}

composeApp/src/iosMain/kotlin/com/slax/reader/domain/auth/AppleSignIn.ios.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ actual class AppleSignInProvider {
1313
actual suspend fun signIn(): Result<AppleSignInResult> =
1414
suspendCancellableCoroutine { continuation ->
1515
val provider = ASAuthorizationAppleIDProvider()
16-
val request = provider.createRequest()
16+
val request = provider.createRequest().apply {
17+
requestedScopes = listOf(
18+
ASAuthorizationScopeFullName,
19+
ASAuthorizationScopeEmail
20+
)
21+
}
1722

1823
val controller = ASAuthorizationController(
1924
authorizationRequests = listOf(request)
@@ -52,8 +57,17 @@ actual class AppleSignInProvider {
5257
controller: ASAuthorizationController,
5358
didCompleteWithError: NSError
5459
) {
60+
if (didCompleteWithError.code < 1002L) {
61+
return
62+
}
63+
val errorMessage = when (didCompleteWithError.code) {
64+
1002L -> "Authorization request not handled"
65+
1003L -> "Authorization request failed"
66+
1004L -> "Authorization request not interactive"
67+
else -> didCompleteWithError.localizedDescription
68+
}
5569
continuation.resume(
56-
Result.failure(Exception(didCompleteWithError.localizedDescription))
70+
Result.failure(Exception(errorMessage))
5771
)
5872
}
5973
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ kotlin.apple.deprecated.allowUsingEmbedAndSignWithCocoaPodsDependencies=true
55
buildkonfig.flavor=dev
66
appVersionName=1.0.1
77
org.gradle.jvmargs=-Xmx4096M -Dfile.encoding\=UTF-8
8-
appVersionCode=677
8+
appVersionCode=679
99
android.useAndroidX=true
1010
kotlin.native.binary.smallBinary=true
1111
ksp.useKSP2=true

iosApp/Versions.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BUNDLE_SHORT_VERSION_STRING = 1.0.1
2-
BUNDLE_VERSION = 677
2+
BUNDLE_VERSION = 679
33
GID_CLIENT_ID = 561250096193-7hjcrkob9cv49gkvt9jn544dsih1oi4g.apps.googleusercontent.com
44
GID_SERVER_CLIENT_ID = 561250096193-gr0t8bc9j9h9hd3rds97vpqd1tq0vq2s.apps.googleusercontent.com
55
GID_REVERSED_CLIENT_ID = com.googleusercontent.apps.561250096193-7hjcrkob9cv49gkvt9jn544dsih1oi4g

0 commit comments

Comments
 (0)