From 2724abcbdb569a2a29386c23e3c5d5c6ce315386 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 30 Jan 2024 13:22:41 +0100 Subject: [PATCH] Fix apple auth triggering automatically --- .../compose/auth/composable/AppleAuth.kt | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/plugins/ComposeAuth/src/appleMain/kotlin/io/github/jan/supabase/compose/auth/composable/AppleAuth.kt b/plugins/ComposeAuth/src/appleMain/kotlin/io/github/jan/supabase/compose/auth/composable/AppleAuth.kt index 6cfdb814..a4e0168a 100644 --- a/plugins/ComposeAuth/src/appleMain/kotlin/io/github/jan/supabase/compose/auth/composable/AppleAuth.kt +++ b/plugins/ComposeAuth/src/appleMain/kotlin/io/github/jan/supabase/compose/auth/composable/AppleAuth.kt @@ -45,29 +45,30 @@ actual fun ComposeAuth.rememberSignInWithApple( val scope = rememberCoroutineScope() LaunchedEffect(key1 = state.started) { - - if (config.loginConfig["apple"] == null) { - fallback.invoke() - state.reset() - return@LaunchedEffect - } - - val appleIDProvider = ASAuthorizationAppleIDProvider() - val request = appleIDProvider.createRequest().apply { - requestedScopes = listOf(ASAuthorizationScopeFullName, ASAuthorizationScopeEmail) - nonce = (config.loginConfig["apple"] as? AppleLoginConfig)?.nonce - } - - val controller = ASAuthorizationController(listOf(request)).apply { - delegate = authorizationController(scope) { - onResult.invoke(it) + if(state.started) { + if (config.loginConfig["apple"] == null) { + fallback.invoke() state.reset() + return@LaunchedEffect } - presentationContextProvider = presentationAnchor() + val appleIDProvider = ASAuthorizationAppleIDProvider() + val request = appleIDProvider.createRequest().apply { + requestedScopes = listOf(ASAuthorizationScopeFullName, ASAuthorizationScopeEmail) + nonce = (config.loginConfig["apple"] as? AppleLoginConfig)?.nonce + } + + val controller = ASAuthorizationController(listOf(request)).apply { + delegate = authorizationController(scope) { + onResult.invoke(it) + state.reset() + } + presentationContextProvider = presentationAnchor() + + } + controller.performRequests() } - controller.performRequests() } return state