dabit3 / gatsby-auth-starter-aws-amplify

Starter Project with Authentication with Gatsby & AWS Amplify
MIT License
324 stars 399 forks source link

Why are we not using `withAuthenticator` with gatsby? #21

Closed aldegoeij closed 5 years ago

aldegoeij commented 5 years ago

The example for React / React Native is very simple using a HOC, but this repo has a more complex setup for Auth, why is that?

See: https://aws-amplify.github.io/docs/js/react#add-auth

Thanks!

aldegoeij commented 5 years ago

If I add:

import Amplify from "aws-amplify"
import awsconfig from "./../aws-exports"
import { withAuthenticator } from "aws-amplify-react" 
Amplify.configure(awsconfig)

Without any actual use, the build-html step of Gatsby crashes with a very weird error:

Error: /Users/alexander/Projects/bodycode/www/public/render-page.js:74355
      {}.DEBUG = namespaces;
        ^
  SyntaxError: Unexpected token .

Referring to render-page.js snippet:

/**
 * Save `namespaces`.
 *
 * @param {String} namespaces
 * @api private
 */

function save(namespaces) {
  if (null == namespaces) {
    // If you set a process.env field to null or undefined, it gets cast to the
    // string 'null' or 'undefined'. Just delete instead.
    delete {}.DEBUG;
  } else {
    {}.DEBUG = namespaces;
  }
}

Is there some kind of expected environment variable that is missing that is causing this? I have no idea how to go about debugging this...

aldegoeij commented 5 years ago

the bug I'm talking about here is worked-around using https://github.com/escaladesports/gatsby-plugin-prefetch-google-fonts/issues/18 and actually related to debug library used as dependency of gatsby.

So you can close the error part of this issue.

Still wondering why you didn't use the HOC though 😄

dabit3 commented 5 years ago

Hey, thanks for the issue! I'm not using withAuthenticator because many people want to have custom control over their auth, so I created this project. I would also suggest using withAuthenticator if it suits your needs though.

dabit3 commented 5 years ago

Also, I've updated the dependencies and upgraded the Gatsby project, this should work now. @aldegoeij

rob94p commented 4 years ago

how would you access the users data after withAuthenticator() has been called and the Auth.currentAuthenticatedUser() has been called. lets say i was using withAuthenticator() to protect a profile page ... as soon as the user is authenticated the profile page will be accessible but the data from that user data is not able to be accessed before that profile page is displayed.