amplify-flutter icon indicating copy to clipboard operation
amplify-flutter copied to clipboard

How to Use auth resources without an Amplify backend?

Open flutterocks opened this issue 1 year ago • 6 comments

Description

There is amplify documentation for React on Use auth resources without an Amplify backend, but there is nothing for Flutter.

Is this possible with amplify in flutter?

Categories

  • [ ] Analytics
  • [ ] API (REST)
  • [ ] API (GraphQL)
  • [X] Auth
  • [X] Authenticator
  • [ ] DataStore
  • [ ] Notifications (Push)
  • [ ] Storage

Steps to Reproduce

n/a

Screenshots

No response

Platforms

  • [ ] iOS
  • [ ] Android
  • [ ] Web
  • [ ] macOS
  • [ ] Windows
  • [ ] Linux

Flutter Version

3.19

Amplify Flutter Version

1.7

Deployment Method

Custom Pipeline

Schema

No response

flutterocks avatar Jun 24 '24 08:06 flutterocks

Hello @flutterocks thank you for submitting this issue. Flutter can use auth resources without an Amplify backend by modifying amplifyconfiguration.dart in gen 1 or modifying amplify_outputs.json in gen 2.

Please let us know if the linked documentation answers your question!

tyllark avatar Jun 24 '24 19:06 tyllark

How do I consume the amplify_outputs.json or generate amplifyconfiguration based on it? I am not using Amplify as a backend, just cognito

flutterocks avatar Jun 24 '24 21:06 flutterocks

If you are not using Amplify at all you can still use the defineBackend function with an empty object and then add your own cognito resources following this example: https://docs.amplify.aws/flutter/build-a-backend/auth/use-existing-cognito-resources/#use-auth-resources-with-an-amplify-backend

You can then use amplify to generate the amplifyconfiguration.dart (npx ampx generate outputs --format dart --outputs-version 0) or amplify_outputs.dart (npx ampx generate outputs --format dart). Note that Amplify Flutter does not yet support amplify_outputs.dart, but should soon.

If you do not want to go that route you could write the amplifyconfiguration.dart (and later amplify_outputs.dart) manually.

Jordan-Nelson avatar Jun 24 '24 22:06 Jordan-Nelson

Ensure you are running ampx commands in root of your project (i.e. in the parent of the 'amplify' directory).

Do I need to create a NPM project to run this?

flutterocks avatar Jun 24 '24 22:06 flutterocks

Yes, you would need to create a npm project. I suggest creating an amplify backend app (npm create amplify@latest -y) but you can then remove the auth/data resources which are added by default.

Jordan-Nelson avatar Jun 25 '24 15:06 Jordan-Nelson

@flutterocks let me know if you have any other questions

Jordan-Nelson avatar Jun 28 '24 20:06 Jordan-Nelson

Ended up getting things to work in a jank way, but I'd recommend improving the docs on this as it's quite confusing. The amplify React docs for using auth resources without an Amplify backend was a breeze to follow

flutterocks avatar Jul 09 '24 02:07 flutterocks

@flutterocks Amplify JS supports configuring Amplify with a JavaScript object. Amplify Flutter requires passing in a string. We have considered accepting a Dart object that would be similar to the JS API. That API might look something like this:

Amplify.configure(
  AmplifyOutputs(
    auth: AuthOutputs(userPoolId: '1234', region: 'us-west-02'),
  ),
);

If you are looking for an API like that, we can turn this into a feature request.

Jordan-Nelson avatar Jul 09 '24 16:07 Jordan-Nelson

@flutterocks I am going to close this out as it sounds like you got this working and I don't believe any docs update is required at this time. The reason that the react docs are clearer is because Amplify JS supports configuring Amplify with a JS object. Amplify Flutter does not support configuring Amplify via a dart object. If you would like to see this supported please open a feature request for it. Thanks.

Jordan-Nelson avatar Jul 11 '24 17:07 Jordan-Nelson