#Amplify Ui - not synchronize user context after login. i must reload the page
1 messages · Page 1 of 1 (latest)
Hi @keen viper , thanks for reaching out! In order to better assist please provide as much detail as you can. Is your usecase the same as the one described in the github issue, are you wanting to use the useAuthenticator hook to set a global authentication state?
yes
i use
"@drowsy elbow-amplify/ui-react": "^5.3.1",
"aws-amplify": "^5.3.11",
i use this:
const container = document.getElementById('root') as HTMLElement
const root = createRoot(container)
root.render(
//<React.StrictMode>
<ColorModeContextProvider>
<BrowserRouter>
<Authenticator.Provider>
<App />
</Authenticator.Provider>
</BrowserRouter>
</ColorModeContextProvider>
//</React.StrictMode>
)
can i provide you something else?
i use typescript instead of javascript
Where/how is useAuthenticator used?
<Authenticator.Provider>
<App />
</Authenticator.Provider> in index.tsx
i look at this: https://ui.docs.amplify.aws/react/guides/auth-protected
Thanks for sharing! One gotcha here is that you must render the Authenticator UI component before using the useAuthenticator hook. You can find the example on our docs in our github repo as well: https://github.com/aws-amplify/amplify-ui/tree/main/guides/react/protected-routes if it's easier to follow that way.
In your index.tsx I would do
const root = createRoot(document.getElementById('app'));
root.render(<App />);
then in App.tsx
function App() {
return (
<Authenticator.Provider>
<MyRoutes />
</Authenticator.Provider>
);
}
then your login route has to wrap the Authenticator component. See https://github.com/aws-amplify/amplify-ui/blob/main/guides/react/protected-routes/src/components/Login.js
emm. it does not work 😦
when i login and try to use " await Auth.updateUserAttributes, context user will not refresh
// MyComponent.js
const { user } = useAuthenticator((context) => [context.user]);
// Here user cannot be used because its not authenticated
user.getUserData()
thanks for help