amazon-archives / awsmobile-cli

CLI experience for Frontend developers in the JavaScript ecosystem.
Apache License 2.0
142 stars 35 forks source link

`publish` seems to disable `aws-amplify-react` `withAuthenticator` #37

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi,

I have a React application that uses Amplify's authenticator, in this fashion:

import {withAuthenticator} from 'aws-amplify-react';
[... bunch of React app code...]
export default withAuthenticator(App);

This works fine on the localhost server I get with awsmobile run. When I launch or refresh the application tab, I have to login.

When I execute awsmobile publish, the resulting S3 & CloudFront URLs bypass authentication, instead going to the first page of my application with all API calls failing since there is no Authorization header.

I was able to work around this by executing npm run build and manually copying the resulting build/ directory to my S3 bucket. The localhost server I get from serve -s build also works.

The contents of the bucket are different when I run awsmobile publish vs. npm run build, too, including lots of aws* files. So I suspect the issue is rooted somewhere in the awsmobile publish code.

UnleashedMind commented 6 years ago

awsmobile publish is a convenience command that carries out these steps in sequence:

  1. awsmobile push
  2. execute the build command you specified during init or by configure
  3. upload the content in the distribution folder you specified during init or configure to the S3 bucket.

If you can get the correct build contents into the build/ directory by npm run build, then awsmobile publish should be able to help you to automate that process if it's correctly configured.

Please run awsmobile configure project and double check the distribution directory and build command are correctly set.

Let us know if you still see issues.

ghost commented 6 years ago

I'm good now, this was indeed an issue with the configuration on my end.

Somewhere along the line I changed from dist/ to build/ and was getting an older version with auth disabled, not the version that had just been built.