2025-03-20 - Frontend Authentication with Redux: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
=concept= | =concept= | ||
*use both of javascript funtion and react | *use both of javascript funtion and react | ||
*use redux for trigger longin in | *use redux for trigger longin in [[2025-034-17 User Detial]] | ||
*trigger another tab is doesn't work for now because each tab has own store login work when use just one tab now | *trigger another tab is doesn't work for now because each tab has own store login work when use just one tab now | ||
*if use more than one tab another tab must refresh to update login | *if use more than one tab another tab must refresh to update login | ||
| Line 19: | Line 19: | ||
== other == | == other == | ||
* [[User Detial]] | * [[2025-034-17 User Detial]] | ||
* [[Frontend Styles]] | * [[Frontend Styles]] | ||
[[Category:Working documents| 2025-03-20]] | [[Category:Working documents| 2025-03-20]] | ||
[[Category:Working documents - Frontend Authentication with Redux| 2025-03-20]] | [[Category:Working documents - Frontend Authentication with Redux| 2025-03-20]] | ||
Revision as of 07:22, 17 April 2025
concept
- use both of javascript funtion and react
- use redux for trigger longin in 2025-034-17 User Detial
- trigger another tab is doesn't work for now because each tab has own store login work when use just one tab now
- if use more than one tab another tab must refresh to update login
Why use Redux
- Single page SPA will render only one time after fist mount component if nothing change like useState hook component will not re-render
- When authentication work done with login and redirect to current page and user-detail component that already mount before login
- User-detail component will not re-render becase it not anything change in component, So they can't see anythig set in local_storage
- If not have access_token component can not querry userId from backend
- If not have userId component can't querry user-detail
- To fix it use redux by change some property in reducer and user-detail will trigger it change by useSelecter then compoonent will re-render
Process
- fist, Component will call loginStart function then check accessToken and accessToken_expire from local storage before login with AWS cognito
- after login with AWS cognito will redirect to login component for get accessToken, accessToken_expire, refresh_token and set them in local_storage
- after everything set before redirect to current page componet will update loginStatus by isLogin property in user_detail reducer for trigger user-detail
- then redirect to current page