9 Jan 2023 to 15 Jan 2023
Weekly forecast
- Work on backend cms
Ask and it will be given to you; seek and you will find; knock and the door will be opened to you. Matthew 7:7
jwt.verify
jwt.verify
will return the decoded payload,usually the username and id inform, if the token and secrete key is correct. the payload can be used in frontend for user access control.
1
2
3
const payload = verifyToken(tokenArray[1]);
req.user = payload;
// here we register the payload to req.user attribute(modify req),and if we put {role:'teacher'} in the payload, we can access req.user later, to check if this user is a teacher(in another middleware).
userSelector 可以取到 store state 中的数据
- 可以在 redux slice 文件中提前将 state 通过箭头函数发送出去.之后通过把该函数在 useSelector 中直接引用来使用.useSelector(slice.fn) will get you the state.which is the same as normal useSelector.
1
const login = useSelector((state) => state.auth.login); //this is the common use
1
2
3
4
// in redux slice
export const selectIsLoggedIn = (state) => state.auth.isLoggedIn;
// in jsx
const login = useSelector(selectIsLoggedIn);
- this two block will get us the same result.
前端的 search 功能
- 把后端的数据保存拿到后,当成 payload 传给 redux.这样 redux 就有了全部的数据,然后再 redux slice 中作 filter,include 之类的.