You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the Authenticator component is dynamically imported, it is unable to find the amplify configuration that was set using Amplify.configure(aws-exports);
To Reproduce
Please see the "Sample Code" section for a reproduction.
Add the Sample Code to a React Amplify webapp
Change awsConfig to include real cognito information
Host the webapp and navigate to the Sample Code in your browser.
Type in a username and password.
Click Sign In
Inspect the console/log information. There should also be a toast that says No userPool
Expected behavior
I expect to be able to dynamically import the Authenticator component and instantiate it.
[x] A flash of text that says: "WAITING FOR DYNAMIC IMPORT"
[x] The Amplify SignIn panel to be displayed
[ ] Sign in should work correctly. What actually happens is that sign in says "No userPool", with the log error: AuthClass - Cannot get the current user because the user pool is missing. Please make sure the Auth module is configured with a valid Cognito User Pool ID
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
OS: macOS
Browser chrome
"@aws-amplify/auth": "^1.2.20",
Additional context
Add any other context about the problem here.
I am using Next.js for server-side rendering. Importing the Amplify Authenticator component breaks server-side-rendering, which is why I am attempting to dynamically import it in componentDidMount; to force the import on the client. There is no debug information about why the component breaks SSR.
Sample code
Include additional sample code or a sample repository to help us reproduce the issue. (Be sure to remove any sensitive data)
// secure-page.tsx
import React from 'react';
import Amplify from 'aws-amplify';
const awsConfig = {
"aws_project_region": "us-east-1",
"aws_cognito_identity_pool_id": "XXX",
"aws_cognito_region": "us-east-1",
"aws_user_pools_id": "us-east-1_XXX",
"aws_user_pools_web_client_id": "XXX",
}
Amplify.configure(awsConfig);
// Initially, the placeholder component is just a div that will not display the children.
let DynamicComponent = () => (<div>WAITING FOR DYNAMIC IMPORT</div>);
class SecurePage extends React.Component {
constructor(props) {
super(props);
this._dynamicImport = this._dynamicImport.bind(this);
}
// Dynamically imports the amplify component and extracts the Authenticator package.
_dynamicImport = async () => {
DynamicComponent = await import('aws-amplify-react').then(package => package.Authenticator);
// We could set a flag in the state, but for simplicity, we just force a rerender.
this.forceUpdate();
}
// Import the component once the component has mounted.
// This forces an import on the client side.
componentDidMount() {
_this.dynamicImport();
}
render(){
<DynamicAuthenticator>Inside Authenticator</DynamicAuthenticator>
}
}
You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.
This is an attempt at a workaround for Auth breaking SSR, as illustrated in these issues:
@ajhool So it looks like you do have multiple versions of the auth module in your project? Perhaps try removing your node modules and reinstalling latest?
Describe the bug
If the Authenticator component is dynamically imported, it is unable to find the amplify configuration that was set using
Amplify.configure(aws-exports)
;To Reproduce
Please see the "Sample Code" section for a reproduction.
No userPool
Expected behavior
I expect to be able to dynamically import the Authenticator component and instantiate it.
[x] A flash of text that says: "WAITING FOR DYNAMIC IMPORT"
[x] The Amplify SignIn panel to be displayed
[ ] Sign in should work correctly. What actually happens is that sign in says "No userPool", with the log error:
AuthClass - Cannot get the current user because the user pool is missing. Please make sure the Auth module is configured with a valid Cognito User Pool ID
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
I am using Next.js for server-side rendering. Importing the Amplify Authenticator component breaks server-side-rendering, which is why I am attempting to dynamically import it in
componentDidMount
; to force the import on the client. There is no debug information about why the component breaks SSR.Sample code
Include additional sample code or a sample repository to help us reproduce the issue. (Be sure to remove any sensitive data)
You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.
This is an attempt at a workaround for Auth breaking SSR, as illustrated in these issues:
#3201
#2054
#3015
The text was updated successfully, but these errors were encountered: