2025-03-17 User Detail: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (Sven the Barbarian moved page 2025-034-17 User Detial to 2025-03-17 User Detail) |
||
| (4 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
=Concept= | =Concept & Process= | ||
*check if login by get access_token from local_storage | *Use useSelecter isLogin in user-detail reducer for get trigger when login process is done | ||
*querry userId from backend if login and set it in local_storage | *check if login by get access_token from local_storage. | ||
*use userId to querry user_detail | *querry userId from backend if login and set it in local_storage. | ||
*Must set | *use userId to querry user_detail. | ||
*Must set User-detal component as parent of menu-output. | |||
=Why user-detail have to set as parent of menu-output= | =Why user-detail have to set as parent of menu-output= | ||
*Menu- | *Menu-Output is always mount on the web page, so every page will see the output menu also makes the user details component always mount. | ||
*If user-detail not mount userdetail can't be query and if userdetail not query component will not know web page already login or not. | *If user-detail not mount userdetail can't be query and if userdetail not query component will not know web page already login or not. | ||
*After login menu-output will check login and decide which component should output between login component and not login component by check user detail had already query user-detail or not. | *After login menu-output will check login and decide which component should output between login component and not login component by check user detail had already query user-detail or not. | ||
= | =Query userId= | ||
==backend== | ==backend== | ||
* | *Phee create api for get user-detail ask Phee if have problem with get userId. | ||
*for query backen that have authentication require send header with query | *for query backen that have authentication require send header with query. | ||
*Example | *Example | ||
<syntaxhighlight lang="JavaScript"> | <syntaxhighlight lang="JavaScript"> | ||
const objBackend = { | const objBackend = { | ||
method: "GET", | method: "GET", | ||
url: "https://xpxz4ia541.execute-api.us-east-2.amazonaws.com/Test/baseUserId/get",//if phee re-deploy service api will change ask | url: "https://xpxz4ia541.execute-api.us-east-2.amazonaws.com/Test/baseUserId/get",//if phee re-deploy service api will change ask Phee if can't connect to api. | ||
headers: { //require for query api backen with auth. | headers: { //require for query api backen with auth. | ||
Authorization: "Bearer " + localStorage.getItem("access_token"), | Authorization: "Bearer " + localStorage.getItem("access_token"), | ||
| Line 27: | Line 28: | ||
}; | }; | ||
const { data: userIdData } = useGetUserIdQuery(objBackend, { | const { data: userIdData } = useGetUserIdQuery(objBackend, { | ||
skip://not query backend if condition true, It | skip://not query backend if condition true, It good way to set condition for query. | ||
!localStorage.getItem("access_token") || | !localStorage.getItem("access_token") || | ||
(localStorage.getItem("access_token") && localStorage.getItem("userId")), | (localStorage.getItem("access_token") && localStorage.getItem("userId")), | ||
}); | }); | ||
</syntaxhighlight> | |||
*backend have to give cors policy to allow frontend can get backend if see erro about cors policy ask Phee set this. | |||
<syntaxhighlight lang="JavaScript"> | |||
"headers": { | |||
"Access-Control-Allow-Origin": "*", | |||
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", | |||
"Access-Control-Allow-Headers": "Content-Type, Authorization" | |||
}, | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 02:40, 18 April 2025
Concept & Process
- Use useSelecter isLogin in user-detail reducer for get trigger when login process is done
- check if login by get access_token from local_storage.
- querry userId from backend if login and set it in local_storage.
- use userId to querry user_detail.
- Must set User-detal component as parent of menu-output.
- Menu-Output is always mount on the web page, so every page will see the output menu also makes the user details component always mount.
- If user-detail not mount userdetail can't be query and if userdetail not query component will not know web page already login or not.
- After login menu-output will check login and decide which component should output between login component and not login component by check user detail had already query user-detail or not.
Query userId
backend
- Phee create api for get user-detail ask Phee if have problem with get userId.
- for query backen that have authentication require send header with query.
- Example
const objBackend = {
method: "GET",
url: "https://xpxz4ia541.execute-api.us-east-2.amazonaws.com/Test/baseUserId/get",//if phee re-deploy service api will change ask Phee if can't connect to api.
headers: { //require for query api backen with auth.
Authorization: "Bearer " + localStorage.getItem("access_token"),
Accept: "application/json",
"Content-Type": "application/json",
},
body: {},
};
const { data: userIdData } = useGetUserIdQuery(objBackend, {
skip://not query backend if condition true, It good way to set condition for query.
!localStorage.getItem("access_token") ||
(localStorage.getItem("access_token") && localStorage.getItem("userId")),
});
- backend have to give cors policy to allow frontend can get backend if see erro about cors policy ask Phee set this.
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization"
},