Open
Description
Description
I am able to sign in using Amplify.Auth.signIn()
which returns an object that confirms successful login. However, when I fetch the session to check if the user is signed in or to retrieve the tokens to call AppSync it returns an object indicating that the user isn't logged in and no tokens are present.
If I use the connected Authenticator component, the component works fine in itself but again since I cannot retrieve the active token I cannot authenticate against my AppSync API.
I am using developing for Linux on WSL. When I deploy to Chrome (WSL) the Auth session behaves normally.
This has ground my project to a halt.
Categories
- Analytics
- API (REST)
- API (GraphQL)
- Auth
- Authenticator
- DataStore
- Notifications (Push)
- Storage
Steps to Reproduce
- Create an Amplify project on WSL with the Linux platform
- Add cognito auth and create and validate a user
- Define a main function as seen below :
main function and log output:
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter/material.dart';
import 'package:klockedin/amplifyconfiguration.dart';
final username = '<insert username>';
final password = '<insert password>';
void main() async {
try {
WidgetsFlutterBinding.ensureInitialized();
await _configureAmplify();
// Attempt 1: basic sign in method
final auth = await Amplify.Auth.signIn(username: username, password: password);
print('MAIN(1): auth: $auth');
// Log output:
//
// flutter: MAIN(1): auth: SignInResult {
// "isSignedIn": true,
// "nextStep": {
// "additionalInfo": {},
// "signInStep": "done",
// "missingAttributes": []
// }
// }
print("MAIN(2): Auth.isSignedIn ${(await Amplify.Auth.fetchAuthSession()).isSignedIn}");
// Log output:
//
// flutter: MAIN(2): Auth.isSignedIn false
// Attempt 2: sign in by getting the Cognito plugin explicitly
final cognitoPlugin = Amplify.Auth.getPlugin(AmplifyAuthCognito.pluginKey);
final auth2 = await cognitoPlugin.signIn(username: username, password: password);
// Log output:
//
print('MAIN(3): auth2: $auth2');
// flutter: MAIN(3): auth2: SignInResult {
// "isSignedIn": true,
// "nextStep": {
// "additionalInfo": {},
// "signInStep": "done",
// "missingAttributes": []
// }
// }
print("MAIN(4): Auth2.isSignedIn ${(await Amplify.Auth.fetchAuthSession()).isSignedIn}");
// Log output:
//
// flutter: MAIN(4): Auth2.isSignedIn false
print("MAIN(5): Auth2.isSignedIn ${(await cognitoPlugin.fetchAuthSession()).isSignedIn}");
// Log output:
//
// flutter: MAIN(5): Auth2.isSignedIn false
} catch (e) {
print('MAIN(6): error: $e');
}
}
Future<void> _configureAmplify() async {
try {
// Add any Amplify plugins you want to use
final authPlugin = AmplifyAuthCognito();
await Amplify.addPlugins([
authPlugin,
// storagePlugin
]);
await Amplify.configure(amplifyConfig);
safePrint('Successfully configured');
} on Exception catch (e) {
safePrint('Error configuring Amplify: $e');
}
}
flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.5, on Debian GNU/Linux 10 (buster) 5.15.167.4-microsoft-standard-WSL2, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2024.2)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!
pubspec (amplify_* deps):
amplify_flutter: ^2.0.0
amplify_auth_cognito: ^2.0.0
amplify_authenticator: ^2.0.0
amplify_storage_s3: ^2.0.0
pubspec.lock (amplify_* deps):
amplify_analytics_pinpoint:
dependency: transitive
description:
name: amplify_analytics_pinpoint
sha256: "383773bca56bb74f0dc20de5c4f9d769e129ef769aff801171f17efaacd10ffe"
url: "https://pub.dev"
source: hosted
version: "2.5.1"
amplify_analytics_pinpoint_dart:
dependency: transitive
description:
name: amplify_analytics_pinpoint_dart
sha256: "820f11b335f3a8cbd6273f3be8fe64812df80e9e56b0d38749982fbc66ff68f8"
url: "https://pub.dev"
source: hosted
version: "0.4.6"
amplify_auth_cognito:
dependency: "direct main"
description:
name: amplify_auth_cognito
sha256: "3dfa0d55fe0e96beacac479dc0821d807957edc8e396d91465ade545a616a5ff"
url: "https://pub.dev"
source: hosted
version: "2.5.0"
amplify_auth_cognito_dart:
dependency: transitive
description:
name: amplify_auth_cognito_dart
sha256: "9b88719e52790d0796cf2d2adfa3b030e4e2954ea9d736b1a932e4a245b01e52"
url: "https://pub.dev"
source: hosted
version: "0.11.7"
amplify_authenticator:
dependency: "direct main"
description:
name: amplify_authenticator
sha256: b3ed04f5334c1169cd21d256ae18811258d72fb727485b2825375a95af5f62a7
url: "https://pub.dev"
source: hosted
version: "2.3.1"
amplify_core:
dependency: transitive
description:
name: amplify_core
sha256: "1143b5486dceccf8a6807234a277b8643edacdcc032b8a2abc4e0125af3e2a65"
url: "https://pub.dev"
source: hosted
version: "2.5.0"
amplify_db_common:
dependency: transitive
description:
name: amplify_db_common
sha256: df14821533f525778ccd58942c137e0ba9b753f4836b152b0211a009ca0b4e3d
url: "https://pub.dev"
source: hosted
version: "0.4.7"
amplify_db_common_dart:
dependency: transitive
description:
name: amplify_db_common_dart
sha256: "1bcedfaf97f156da38661ddf89532a21cf801adff9146cd8aac3663c4572f034"
url: "https://pub.dev"
source: hosted
version: "0.4.7"
amplify_flutter:
dependency: "direct main"
description:
name: amplify_flutter
sha256: "1aed48ff57761e4ba342a6a2103376de69a52cb988b77c7097eb0cf93ce9535f"
url: "https://pub.dev"
source: hosted
version: "2.5.0"
amplify_secure_storage:
dependency: transitive
description:
name: amplify_secure_storage
sha256: "432440443dc5ef9552e6ef20094bd15d2d4aa776eed17f9d756b2673e9c789a6"
url: "https://pub.dev"
source: hosted
version: "0.5.7"
amplify_secure_storage_dart:
dependency: transitive
description:
name: amplify_secure_storage_dart
sha256: ec4871ff70c0487ea03b2fd03d2f0328d9b3b9e8b0305aab5a040f6ac3c4bb15
url: "https://pub.dev"
source: hosted
version: "0.5.3"
amplify_storage_s3:
dependency: "direct main"
description:
name: amplify_storage_s3
sha256: bbb0584de999a0c9f639dd96ea5c26daff993eb51912feda5775be229116c567
url: "https://pub.dev"
source: hosted
version: "2.5.1"
amplify_storage_s3_dart:
dependency: transitive
description:
name: amplify_storage_s3_dart
sha256: "9e32c2e87422bf8236993e91c47f9da5bc292383329ec4ecf079ac8841a23f5b"
url: "https://pub.dev"
source: hosted
version: "0.4.7"
Screenshots
No response
Platforms
- iOS
- Android
- Web
- macOS
- Windows
- Linux
Flutter Version
3.24.5
Amplify Flutter Version
2.5.0
Deployment Method
Amplify Gen 2
Schema
No response