-
로그인 상태관리멈멈-토이프로젝트(React)1 2024. 4. 20. 23:25728x90
로그인 한 후 유저의 uid를 상태관리로 관리하기
Slice
//초기 값 const initialState = { userId: "", }; const userLoginSlice = createSlice({ name: "userUid", initialState, reducers: { userLogin: (state, action) => { const user = action.payload; console.log(user); state.userId = user; console.log(user); }, }, }); export const { userLogin, } = userLoginSlice.actions; export default userLoginSlice.reducer;
login
const userUidFunc = async () => { const { data: { user }, } = await supabase.auth.getUser(); if (user) { setUserUid(user.id); dispatch(userLogin(user.id)); console.log("사용자 정보:", user.id); } };
'멈멈-토이프로젝트(React)1' 카테고리의 다른 글
수파베이스 에러 missing FROM-clause entry for table (0) 2024.04.26 에러 A non-serializable value was detected in an action (0) 2024.04.23 수파베이스 CLI (0) 2024.04.11 이미지 출력 하기 (0) 2024.04.04 수파베이스 사용자 정보 가져 오기 (0) 2024.04.03