I have a React App and I am trying to use AWS Cognito. However, as soon as I refresh the page (a fairly normal action for any end-user, the user is no longer authenticated. I’m confused about what to do about this. Any suggestions? Sorry, I’m a newbie
I’m not using Amplify. I’m not sure how much it’ll end up costing me and am fairly constrained on budget. Is that silly? Should Amplify on free trial be okay?
If you want the most simple answer, then just use sessionStorage. But if this is for a larger AWS related project, AWS Amplify does reduce a lot of complexity long term.
General procedure: Once the token is retrieved store it in the application’s memory.
Where in the memory depends on your design. It could be cookies, local storage, session storage, etc, (Any sort of cache or application memory you have available)
Make sure to add a time to live if you store it on cache/local storage/cookies.
Specific implementation:
Use next-auth (https://next-auth.js.org/providers) to handle the process for you. Consume your 0Auth2 flow from Cognito (or the flow you are using to retrieve the tokens) and you are done.
Sure. But he says “Sorry, I’m a newbie” which is probably a strong indicator that the need for home grown auth code is not there for this particular thread. And the tone seems to indicate wanting auth to just work, not necessarily that OP is trying to learn auth techniques.