Skip to content

Commit

Permalink
fix(datastore): Use platform thread (#3607)
Browse files Browse the repository at this point in the history
The call from Native -> Dart to retrieve Auth credentials is being performed on a background thread which results in the following warning message.

```
The 'dev.flutter.pigeon.NativeAuthPlugin.fetchAuthSession' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.
```
  • Loading branch information
dnys1 committed Aug 30, 2023
1 parent b7d8fc5 commit 36ee2f0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/amplify_datastore/ios/Classes/CognitoPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ public class CognitoPlugin: AuthCategoryPlugin {
request: AuthFetchSessionRequest(options: options ?? AuthFetchSessionRequest.Options()),
resultListener: listener
)
nativeAuthPlugin.fetchAuthSession { session in
let result = NativeAWSAuthCognitoSession(from: session)
operation.dispatch(result: .success(result))
DispatchQueue.main.async {
self.nativeAuthPlugin.fetchAuthSession { session in
let result = NativeAWSAuthCognitoSession(from: session)
operation.dispatch(result: .success(result))
}
}
return operation
}
Expand Down

0 comments on commit 36ee2f0

Please sign in to comment.