@@ -42,6 +42,7 @@ import kotlinx.coroutines.launch
4242
4343enum class EmailAuthMode {
4444 SignIn ,
45+ EmailLinkSignIn ,
4546 SignUp ,
4647 ResetPassword ,
4748}
@@ -103,6 +104,7 @@ class EmailAuthContentState(
103104 val onGoToSignUp : () -> Unit ,
104105 val onGoToSignIn : () -> Unit ,
105106 val onGoToResetPassword : () -> Unit ,
107+ val onGoToEmailLinkSignIn : () -> Unit ,
106108)
107109
108110/* *
@@ -133,7 +135,13 @@ fun EmailAuthScreen(
133135 val dialogController = LocalTopLevelDialogController .current
134136 val coroutineScope = rememberCoroutineScope()
135137
136- val mode = rememberSaveable { mutableStateOf(EmailAuthMode .SignIn ) }
138+ // Start in EmailLinkSignIn mode if coming from cross-device flow
139+ val initialMode = if (emailLinkFromDifferentDevice != null && provider.isEmailLinkSignInEnabled) {
140+ EmailAuthMode .EmailLinkSignIn
141+ } else {
142+ EmailAuthMode .SignIn
143+ }
144+ val mode = rememberSaveable { mutableStateOf(initialMode) }
137145 val displayNameValue = rememberSaveable { mutableStateOf(" " ) }
138146 val emailTextValue = rememberSaveable { mutableStateOf(" " ) }
139147 val passwordTextValue = rememberSaveable { mutableStateOf(" " ) }
@@ -222,37 +230,13 @@ fun EmailAuthScreen(
222230 onSignInClick = {
223231 coroutineScope.launch {
224232 try {
225- when {
226- emailLinkFromDifferentDevice != null -> {
227- authUI.signInWithEmailLink(
228- context = context,
229- config = configuration,
230- provider = provider,
231- email = emailTextValue.value,
232- emailLink = emailLinkFromDifferentDevice,
233- )
234- }
235-
236- provider.isEmailLinkSignInEnabled -> {
237- authUI.sendSignInLinkToEmail(
238- context = context,
239- config = configuration,
240- provider = provider,
241- email = emailTextValue.value,
242- credentialForLinking = authCredentialForLinking,
243- )
244- }
245-
246- else -> {
247- authUI.signInWithEmailAndPassword(
248- context = context,
249- config = configuration,
250- email = emailTextValue.value,
251- password = passwordTextValue.value,
252- credentialForLinking = authCredentialForLinking,
253- )
254- }
255- }
233+ authUI.signInWithEmailAndPassword(
234+ context = context,
235+ config = configuration,
236+ email = emailTextValue.value,
237+ password = passwordTextValue.value,
238+ credentialForLinking = authCredentialForLinking,
239+ )
256240 } catch (e: Exception ) {
257241 onError(AuthException .from(e))
258242 }
@@ -261,7 +245,15 @@ fun EmailAuthScreen(
261245 onSignInEmailLinkClick = {
262246 coroutineScope.launch {
263247 try {
264- if (provider.isEmailLinkSignInEnabled) {
248+ if (emailLinkFromDifferentDevice != null ) {
249+ authUI.signInWithEmailLink(
250+ context = context,
251+ config = configuration,
252+ provider = provider,
253+ email = emailTextValue.value,
254+ emailLink = emailLinkFromDifferentDevice,
255+ )
256+ } else {
265257 authUI.sendSignInLinkToEmail(
266258 context = context,
267259 config = configuration,
@@ -315,6 +307,10 @@ fun EmailAuthScreen(
315307 textValues.forEach { it.value = " " }
316308 mode.value = EmailAuthMode .ResetPassword
317309 },
310+ onGoToEmailLinkSignIn = {
311+ textValues.forEach { it.value = " " }
312+ mode.value = EmailAuthMode .EmailLinkSignIn
313+ },
318314 )
319315
320316 if (content != null ) {
@@ -345,9 +341,23 @@ private fun DefaultEmailAuthContent(
345341 onEmailChange = state.onEmailChange,
346342 onPasswordChange = state.onPasswordChange,
347343 onSignInClick = state.onSignInClick,
348- onSignInWithEmailLink = state.onSignInEmailLinkClick,
349344 onGoToSignUp = state.onGoToSignUp,
350345 onGoToResetPassword = state.onGoToResetPassword,
346+ onGoToEmailLinkSignIn = state.onGoToEmailLinkSignIn,
347+ onNavigateBack = onCancel
348+ )
349+ }
350+
351+ EmailAuthMode .EmailLinkSignIn -> {
352+ SignInEmailLinkUI (
353+ configuration = configuration,
354+ email = state.email,
355+ isLoading = state.isLoading,
356+ emailSignInLinkSent = state.emailSignInLinkSent,
357+ onEmailChange = state.onEmailChange,
358+ onSignInWithEmailLink = state.onSignInEmailLinkClick,
359+ onGoToSignIn = state.onGoToSignIn,
360+ onGoToResetPassword = state.onGoToResetPassword,
351361 onNavigateBack = onCancel
352362 )
353363 }
0 commit comments