Skip to content

Commit f2db38c

Browse files
dnys1Dillon Nys
authored andcommitted
fix(datastore): Use platform thread (#3607)
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. ```
1 parent daaa260 commit f2db38c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/amplify_datastore/ios/Classes/CognitoPlugin.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ public class CognitoPlugin: AuthCategoryPlugin {
6262
request: AuthFetchSessionRequest(options: options ?? AuthFetchSessionRequest.Options()),
6363
resultListener: listener
6464
)
65-
nativeAuthPlugin.fetchAuthSession { session in
66-
let result = NativeAWSAuthCognitoSession(from: session)
67-
operation.dispatch(result: .success(result))
65+
DispatchQueue.main.async {
66+
self.nativeAuthPlugin.fetchAuthSession { session in
67+
let result = NativeAWSAuthCognitoSession(from: session)
68+
operation.dispatch(result: .success(result))
69+
}
6870
}
6971
return operation
7072
}

0 commit comments

Comments
 (0)