-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Documentation does not specify how to handle return from successful hosted UI authentication #1386
Comments
@elorzafe I have the exact same problem! Been trying to find a solution for days now. |
yes! same problem with my angular app. |
@tunecrew Hi, I can answer your first question. You can use the import { Auth, Hub } from 'aws-amplify';
class myComp extends Component {
componentDidMount() {
Hub.listen('auth', this);
}
onHubCapsule(capsule) {
const { channel, payload, source } = capsule;
if (channel === 'auth' && payload.event === 'signIn') {
this.checkUser();
}
}
checkUser() {
Auth.currentAuthenticatedUser().then(() => {
});
}
} |
@powerful23 for reference: https://hackernoon.com/modular-imports-with-aws-amplify-daeb387b6985 |
@jadbox you can do |
@powerful23 thanks that works... Hub doesn't have a Typescript definition on the
|
@powerful23 thanks for this - it does work - a few comments:
I'm fairly new to React so it is quite possible I'm missing some obvious ways of doing things, but I would think if the Amplify React components were a bit more complete in dealing with these kind of things people could get up and running w/ Cognito much quicker (not insulting the team's efforts at all, just an opinion on which way to go with things!). |
I'm also having problems with the authentication persisting. Once being logged in successfully in my app with the Code token, if I redirect to remove the code... Amplify no longer recognizes that I was authenticated. I have tried both cookies and localstorage options without success. Maybe I'm missing something? |
@jadbox I'm not having that problem - I am not using cookies but I'm not sure what you mean by "localhost options" |
@tunecrew I can answer the second question. I agree to add a state like @jadbox How are you redirecting your app? The code returned by Cognito will be used to revoke another call to get you the tokens for Auth so if you redirect your app before this process gets completed then you won't be signed in successfully. |
I meant "localstorage", lol. Corrected the mistake above. |
@jadbox calling Auth.currentAuthenticatedUser() seems to be what reads the |
@tunecrew is there a different promise other than currentAuthenticatedUser for when the user should be authenticated what the data is in localstorage rather than coming from uri query |
@jadbox I'll try and go a gist w/ my code. |
Can someone point me to the documentation and examples for implementing Cognito Hosted UI on the client side? React, angular, vanilla is all fine. I've been googling for a long time and this is the closest thing I've been able to find. Is it correct that amazon-cognito-identity-js is purely for implementing the Cognito Signin/Signup APIs directly (not Hosted UI)? |
If your app is not SSR, and you do not need to serialize your redux store, you can simply store your Cognito object in redux. Don't forget to reset your reducers to initialState on logout. This is my example of signIn redux-thunk action with immutable.js, but it general you should get an idea. history object I get from withRouter() HOC from 'react-router v4` in login button component. This is not the best example thou it does work. If somebody have better ideas, please share. In my case mutable Cognito object with methods is not serializable in context of otherwise completely immutable state. There should be a better way to handle Cognito object outside of redux store.
|
I have one issue with this method. If I use it on my home page, then a user signs in later through a different page. The home page listener still fires and I get the warning about component not mounted:
Does anyone know how I can unsubscribe to this when my Home component unmounts? Thanks a lot. |
@uclaeamsavino thanks for you feedback. The reason why you need to listen on Hub events before calling The Hub module is just a very simple implementation for the local events subscription. We will improve that category in the future for more generic use. Unfortunately for now it doesn't provide the method to unsubscribe the listener. Will create a story for that. |
We are having the same problem where our users see our login UI for a few seconds when they are redirected back from Cognito Hosted UI. |
So, did you end up with a full example? This is still very interesting! |
For those of you who want a quick solution, I just implemented my own mechanism to dispatch and listen to 'isAuthenticating' event. Use it at your own risk.
|
Hello everyone, we have created an RFC for feature work that should make the challenges found in this issue easier in the future. If you have a moment please read through the details and add any comments: #2716 Your feedback in the RFC will help us ensure that we are delivering the best experience possible. Thank you. |
Hi, @undefobj - the proposed changes in #2716 look promising. I'm not quite sure how they will affect the lag after successful authentication where we see the sign in component displayed briefly. Will you be implementing @powerful23's suggestion of adding the |
a good example is provided in https://aws-amplify.github.io/docs/js/authentication#make-it-work-in-your-app partial code snippet:
|
@tunecrew we recently did an update about how to use hosted UI in the doc: https://aws-amplify.github.io/docs/js/authentication#oauth-and-hosted-ui I am going to close this issue. Please let me know if you want to reopen it. |
I am facing this exact same problem. Is there a way around it ? |
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 |
Given a generic
npx create-react-app . ; npm install aws-amplify-react
app with the following App.js:Authentication is successful and the hosted UI redirects back to
http://localhost:3000/?code=...
At this point, however, the Log In button is still displayed and
isAuthenticated
is still false, although the call toAuth.currentAuthenticatedUser()
has been successful and the access, id and refresh tokens have been added to local storage.Reloading the page changes the state of
isAuthenticated
to true and everything works as expected, although the?code=...
query parameter is still present in the url.It would be of great help if the documentation provided a simple example like this illustrating the following:
code
query parameter without a manual redirectI'm wondering also if there is some complete other aspect of this missing - like having to also listen to the auth events from Hub and then respond (btw the documentation on Hub seems extremely sparse)
The text was updated successfully, but these errors were encountered: