Merge remote-tracking branch 'upstream/master' into feat/image-upload
This commit is contained in:
commit
223dd280d4
5 files changed
+30
-11
No files matched your search
@@ -67,10 +67,8 @@ const handleAuthFulfilled = (state, action) => {
|
|||||||
state.isLoading = false;
|
state.isLoading = false;
|
||||||
state.success = action.payload.success;
|
state.success = action.payload.success;
|
||||||
state.msg = action.payload.msg;
|
state.msg = action.payload.msg;
|
||||||
state.authToken = action.payload.data;
|
state.authToken = action.payload.data.token;
|
||||||
const decodedToken = jwtDecode(action.payload.data);
|
state.user = action.payload.data.user;
|
||||||
const user = { ...decodedToken };
|
|
||||||
state.user = user;
|
|
||||||
};
|
};
|
||||||
const handleAuthRejected = (state, action) => {
|
const handleAuthRejected = (state, action) => {
|
||||||
state.isLoading = false;
|
state.isLoading = false;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ const Register = () => {
|
|||||||
lastname: "",
|
lastname: "",
|
||||||
email: "",
|
email: "",
|
||||||
password: "",
|
password: "",
|
||||||
|
role: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -50,7 +51,7 @@ const Register = () => {
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
}, [navigate]);
|
}, [form, navigate]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { error } = registerValidation.validate(form, {
|
const { error } = registerValidation.validate(form, {
|
||||||
@@ -76,8 +77,9 @@ const Register = () => {
|
|||||||
const handleSubmit = async (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
await registerValidation.validateAsync(form, { abortEarly: false });
|
const adminForm = { ...form, role: "admin" };
|
||||||
const action = await dispatch(register(form));
|
await registerValidation.validateAsync(adminForm, { abortEarly: false });
|
||||||
|
const action = await dispatch(register(adminForm));
|
||||||
|
|
||||||
if (action.meta.requestStatus === "fulfilled") {
|
if (action.meta.requestStatus === "fulfilled") {
|
||||||
const token = action.payload.data;
|
const token = action.payload.data;
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ const registerValidation = joi.object({
|
|||||||
"string.min": "Password must be at least 8 characters",
|
"string.min": "Password must be at least 8 characters",
|
||||||
"string.empty": "Password is required",
|
"string.empty": "Password is required",
|
||||||
}),
|
}),
|
||||||
|
role: joi.string().required().messages({
|
||||||
|
"string.empty": "Role is required",
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const loginValidation = joi.object({
|
const loginValidation = joi.object({
|
||||||
|
|||||||
+13
-1
@@ -2,12 +2,24 @@ import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
|||||||
import monitorsReducer from "./Features/Monitors/monitorsSlice";
|
import monitorsReducer from "./Features/Monitors/monitorsSlice";
|
||||||
import authReducer from "./Features/Auth/authSlice";
|
import authReducer from "./Features/Auth/authSlice";
|
||||||
import storage from "redux-persist/lib/storage";
|
import storage from "redux-persist/lib/storage";
|
||||||
import { persistReducer, persistStore } from "redux-persist";
|
import { persistReducer, persistStore, createTransform } from "redux-persist";
|
||||||
|
|
||||||
|
const authTransform = createTransform(
|
||||||
|
(inboundState) => {
|
||||||
|
const { profileImage, ...rest } = inboundState;
|
||||||
|
return rest;
|
||||||
|
},
|
||||||
|
// No transformation on rehydration
|
||||||
|
null,
|
||||||
|
// Only applies to auth
|
||||||
|
{ whitelist: ["auth"] }
|
||||||
|
);
|
||||||
|
|
||||||
const persistConfig = {
|
const persistConfig = {
|
||||||
key: "root",
|
key: "root",
|
||||||
storage,
|
storage,
|
||||||
whitielist: ["auth", "monitors"],
|
whitielist: ["auth", "monitors"],
|
||||||
|
transforms: [authTransform],
|
||||||
};
|
};
|
||||||
|
|
||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
|
|||||||
@@ -55,7 +55,11 @@ const registerController = async (req, res, next) => {
|
|||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
userId: newUser._id,
|
userId: newUser._id,
|
||||||
});
|
});
|
||||||
const token = issueToken(newUser._doc);
|
|
||||||
|
const userForToken = { ...newUser._doc };
|
||||||
|
delete userForToken.profileImage;
|
||||||
|
|
||||||
|
const token = issueToken(userForToken);
|
||||||
|
|
||||||
// Sending email to user with pre defined template
|
// Sending email to user with pre defined template
|
||||||
const template = registerTemplate("https://www.bluewavelabs.ca");
|
const template = registerTemplate("https://www.bluewavelabs.ca");
|
||||||
@@ -69,7 +73,7 @@ const registerController = async (req, res, next) => {
|
|||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: successMessages.AUTH_CREATE_USER,
|
msg: successMessages.AUTH_CREATE_USER,
|
||||||
data: token,
|
data: { user: newUser, token: token },
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
@@ -108,7 +112,7 @@ const loginController = async (req, res, next) => {
|
|||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: successMessages.AUTH_LOGIN_USER,
|
msg: successMessages.AUTH_LOGIN_USER,
|
||||||
data: token,
|
data: { user: userWithoutPassword, token: token },
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.status = 500;
|
error.status = 500;
|
||||||
|
|||||||
Reference in new issue
Block a user