mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2025-05-17 03:48:06 +08:00
Added functional registration
This commit is contained in:
parent
dfc20753b3
commit
26b3db25f0
23 changed files with 679 additions and 57 deletions
14
src/features/redux/Store/Store.tsx
Normal file
14
src/features/redux/Store/Store.tsx
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import AuthReducer from "../slices/AuthSlice/AuthSlice";
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
auth: AuthReducer,
|
||||
},
|
||||
});
|
||||
|
||||
export default store;
|
||||
|
||||
// Infer the `RootState` and `AppDispatch` types from the store itself
|
||||
export type RootState = ReturnType<typeof store.getState>;
|
||||
export type AppDispatch = typeof store.dispatch;
|
42
src/features/redux/slices/AuthSlice/AuthSlice.tsx
Normal file
42
src/features/redux/slices/AuthSlice/AuthSlice.tsx
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
export const AuthSlice = createSlice({
|
||||
name: "Auth",
|
||||
initialState: {
|
||||
creds: {
|
||||
email: "",
|
||||
uid: "",
|
||||
username: "",
|
||||
full_name: "",
|
||||
token: "",
|
||||
},
|
||||
},
|
||||
reducers: {
|
||||
setToken: (state, action) => {
|
||||
state.creds.token = action.payload.token;
|
||||
},
|
||||
setUser: (state, action) => {
|
||||
state.creds = {
|
||||
email: action.payload.email,
|
||||
uid: action.payload.uid,
|
||||
username: action.payload.username,
|
||||
full_name: action.payload.full_name,
|
||||
token: action.payload.token,
|
||||
};
|
||||
},
|
||||
clear: (state) => {
|
||||
state.creds = {
|
||||
email: "",
|
||||
uid: "",
|
||||
username: "",
|
||||
full_name: "",
|
||||
token: "",
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Action creators are generated for each case reducer function
|
||||
export const { setToken, setUser, clear } = AuthSlice.actions;
|
||||
|
||||
export default AuthSlice.reducer;
|
Loading…
Add table
Add a link
Reference in a new issue