Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-amplify/ui-react - renders component when user is not signed in #5547

Closed
onlybakam opened this issue Apr 24, 2020 · 11 comments · Fixed by #5641
Closed

aws-amplify/ui-react - renders component when user is not signed in #5547

onlybakam opened this issue Apr 24, 2020 · 11 comments · Fixed by #5641
Assignees
Labels
Auth Related to Auth components/category investigating This issue is being investigated UI Related to UI Components

Comments

@onlybakam
Copy link
Contributor

Describe the bug

@aws-amplify/ui-react": "^0.2.3

With

export default withAuthenticator(App)

user is not signed in but App is still "rendered" (though not visible). The useEffect hooks are triggered, indicated that it was rendered. the App should not be rendered until a user has signed in.

@onlybakam onlybakam added the to-be-reproduced Used in order for Amplify to reproduce said issue label Apr 24, 2020
@ashika01 ashika01 self-assigned this Apr 24, 2020
@ashika01
Copy link
Contributor

ashika01 commented Apr 24, 2020

@onlybakam : could you provide us with a sample of your code?

@onlybakam
Copy link
Contributor Author

import Amplify from 'aws-amplify'
import { withAuthenticator } from '@aws-amplify/ui-react'
Amplify.configure(awsconfig)

function App() {
  React.useEffect(() => {
    console.log('called') // <- logged even if user is not authenticated
  }, [])
  return (

    <div>hi</div>
  )
}

export default withAuthenticator(App)

@onlybakam
Copy link
Contributor Author

expectation is that App is not rendered if state is not signedIn. so something like

{state.signedIn ? <Component /> : null}

image

@jordanranz jordanranz self-assigned this Apr 24, 2020
@ashika01 ashika01 removed their assignment Apr 24, 2020
@jordanranz jordanranz added Auth Related to Auth components/category and removed to-be-reproduced Used in order for Amplify to reproduce said issue labels Apr 24, 2020
@jordanranz
Copy link
Contributor

Investigating a change to this behavior

@jordanranz
Copy link
Contributor

The auth state handling is now baked into the withAuthenticator. Please try the @aws-amplify/ui-react@unstable. Working on documenting the same behavior for AmplifyAuthenticator

@mtliendo
Copy link

mtliendo commented May 4, 2020

Hey @jordanranz thanks for all your work on the the amplify components and quick turnaround times on issues/feedback!

I was wanting to make a suggestion in holding off on closing issues until any changes are pushed to the main library as opposed to @unstable.

My use case is that I have a few blog posts coming out regarding the auth components, but want to avoid using the @unstable package. It would be easier for tracking if I could follow open issues.

@kmbro
Copy link

kmbro commented May 21, 2020

Any update on the AmplifyAuthenticator version of this? I am seeing this issue, and seems to be a very strange behavior.

v2, which I use in different projects does not render the app, but here I have the following:

const App = () => (
  <AmplifyAuthenticator>
    {/* Customize Amplify Auth Components (https://docs.amplify.aws/ui/auth/authenticator/q/framework/react#sign-up) */}
    {AuthenticationComponents}

    {/* Application */}
    <Provider store={store}>
      <Router>
        <Navigation defaultExpand={true}>
          {/* Main content */}
          <Routes />
        </Navigation>
      </Router>
    </Provider>
  </AmplifyAuthenticator>
);

export default App;

Where AuthenticationComponents are my custom SignIn/SIgnUp components as a list. I can view everything below <Provider> if I am signed in or not.

Could you advise on how to use your fix if it is already in master? or if not, can I follow your merge request when you put it up? thanks

@trungtin
Copy link

any update on the Authenticator component part? Still having problem with @aws-amplify/[email protected]
Thanks

@jordanranz
Copy link
Contributor

@mtliendo this is good feedback. It auto closes from the hook in the PR but it may be better to hold off on using that.

@kmbro and @trungtin, this is a known limitation to the web component default slot. The recommended way to to manage the application mounting would be to use this guide: https://docs.amplify.aws/ui/auth/authenticator/q/framework/react#manage-auth-state-and-conditional-app-rendering

@kmbro
Copy link

kmbro commented Sep 18, 2020

@jordanranz This worked great for me. Thanks for the linked doc above!

@ErikCH ErikCH added UI Related to UI Components and removed Amplify UI Components labels May 19, 2021
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Auth Related to Auth components/category investigating This issue is being investigated UI Related to UI Components
Projects
None yet
8 participants