Skip to content

Commit 6ed2d1f

Browse files
committed
updated example.md file
1 parent 61e92fe commit 6ed2d1f

1 file changed

Lines changed: 24 additions & 23 deletions

File tree

EXAMPLES.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -327,34 +327,35 @@ WebAuthProvider.logout(account)
327327
328328
## Handling Configuration Changes During Authentication
329329

330-
When the Activity is destroyed during authentication due to a configuration change (e.g. device rotation, locale change, dark mode toggle), the SDK caches the authentication result internally. Use `consumePendingLoginResult()` or `consumePendingLogoutResult()` in your `onResume()` to recover it.
330+
When the Activity is destroyed during authentication due to a configuration change (e.g. device rotation, locale change, dark mode toggle), the SDK caches the authentication result internally. Call `WebAuthProvider.attach()` in your `onResume()` to recover it. This single call handles both recovery scenarios:
331+
332+
- **Configuration change**: delivers any cached result immediately to the callback
333+
- **Process death**: registers `loginCallback` as a listener and auto-removes it when the Activity is destroyed
331334

332335
```kotlin
333336
class LoginActivity : AppCompatActivity() {
334337

335-
private val loginCallback = object : Callback<Credentials, AuthenticationException> {
336-
override fun onSuccess(result: Credentials) {
337-
// Handle successful login
338-
}
339-
override fun onFailure(error: AuthenticationException) {
340-
// Handle error
341-
}
342-
}
343-
344-
private val logoutCallback = object : Callback<Void?, AuthenticationException> {
345-
override fun onSuccess(result: Void?) {
346-
// Handle successful logout
347-
}
348-
override fun onFailure(error: AuthenticationException) {
349-
// Handle error
350-
}
351-
}
352-
353338
override fun onResume() {
354339
super.onResume()
355-
// Recover any result that arrived while the Activity was being recreated
356-
WebAuthProvider.consumePendingLoginResult(loginCallback)
357-
WebAuthProvider.consumePendingLogoutResult(logoutCallback)
340+
WebAuthProvider.attach(
341+
lifecycleOwner = this,
342+
loginCallback = object : Callback<Credentials, AuthenticationException> {
343+
override fun onSuccess(result: Credentials) {
344+
// Handle successful login
345+
}
346+
override fun onFailure(error: AuthenticationException) {
347+
// Handle error
348+
}
349+
},
350+
logoutCallback = object : Callback<Void?, AuthenticationException> {
351+
override fun onSuccess(result: Void?) {
352+
// Handle successful logout
353+
}
354+
override fun onFailure(error: AuthenticationException) {
355+
// Handle error
356+
}
357+
}
358+
)
358359
}
359360

360361
fun onLoginClick() {
@@ -372,7 +373,7 @@ class LoginActivity : AppCompatActivity() {
372373
```
373374

374375
> [!NOTE]
375-
> If you use the `suspend fun await()` API from a ViewModel coroutine scope, the Activity is never captured in the callback chain, so you do not need `consumePending*` calls.
376+
> If you use the `suspend fun await()` API from a ViewModel coroutine scope, the Activity is never captured in the callback chain, so you do not need `attach()` calls.
376377
377378
## Authentication API
378379

0 commit comments

Comments
 (0)