Commit 0f5f6b65 authored by janithGamage's avatar janithGamage

fix: update

Desc :update project
parent 20cb9f30
......@@ -43,8 +43,12 @@ export const signUp = async (req, res) => {
if (lastName === null || typeof lastName == "undefined") return res.status(400).json({ code: "02", message: "Last Name Field Required" })
if (contactNumber === null || typeof contactNumber == "undefined") return res.status(400).json({ code: "02", message: "Contact Number Field Required" })
const existingUser = await User.findOne({ email: email })
if (existingUser) return res.status(400).json({ code: "02", message: "User already exist" })
const existingUserByEmail = await User.findOne({ email: email })
if (existingUserByEmail) return res.status(400).json({ code: "02", message: "User already exist" })
const existingUserByContactNo = await User.findOne({ contactNumber: contactNumber })
if (existingUserByContactNo) return res.status(400).json({ code: "02", message: "User already exist" })
if (password === null || typeof password == "undefined") return res.status(400).json({ code: "02", message: "Password Field Required" })
if (password !== confirmPassword) return res.status(400).json({ code: "02", message: "Password doesn't match" })
......
......@@ -16,8 +16,7 @@ const userSchema = mongoose.Schema({
},
contactNumber: {
type: String,
required: true,
unique: true
required: true,
},
password: {
type: String,
......
......@@ -125,9 +125,8 @@ export const JWTProvider = ({ children }: { children: React.ReactElement }) => {
};
const registerUser = async (email: string, password: string, firstName: string, lastName: string, contactNumber: string, confirmPassword: string) => {
// todo: this flow need to be recode as it not verified
const id = chance.bb_pin();
const response = await axiosServices.post('/rest_node/user/sign-up', {
const response = await axiosServices.post('/rest_node/user/sign-up', {
firstName,
lastName,
email,
......@@ -135,24 +134,36 @@ export const JWTProvider = ({ children }: { children: React.ReactElement }) => {
password,
confirmPassword,
type: "member"
});
let users = response.data;
});
const user = response.data.result;
if (window.localStorage.getItem('users') !== undefined && window.localStorage.getItem('users') !== null) {
const localUsers = window.localStorage.getItem('users');
users = [
const users = [
...JSON.parse(localUsers!),
{
id,
email,
password,
name: `${firstName} ${lastName}`
id: user._id,
email: user.email,
password: user.password,
name: `${user.firstName} ${user.lastName}`
}
];
window.localStorage.setItem('users', JSON.stringify(users));
} else {
const users = [
{
id: user._id,
email: user.email,
password: user.password,
name: `${user.firstName} ${user.lastName}`
}
];
window.localStorage.setItem('users', JSON.stringify(users));
}
window.localStorage.setItem('users', JSON.stringify(users));
};
const logout = () => {
setSession(null);
dispatch({ type: LOGOUT });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment