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) => { ...@@ -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 (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" }) 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 }) const existingUserByEmail = await User.findOne({ email: email })
if (existingUser) return res.status(400).json({ code: "02", message: "User already exist" }) 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 === 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" }) if (password !== confirmPassword) return res.status(400).json({ code: "02", message: "Password doesn't match" })
......
...@@ -17,7 +17,6 @@ const userSchema = mongoose.Schema({ ...@@ -17,7 +17,6 @@ const userSchema = mongoose.Schema({
contactNumber: { contactNumber: {
type: String, type: String,
required: true, required: true,
unique: true
}, },
password: { password: {
type: String, type: String,
......
...@@ -125,8 +125,7 @@ export const JWTProvider = ({ children }: { children: React.ReactElement }) => { ...@@ -125,8 +125,7 @@ export const JWTProvider = ({ children }: { children: React.ReactElement }) => {
}; };
const registerUser = async (email: string, password: string, firstName: string, lastName: string, contactNumber: string, confirmPassword: string) => { 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, firstName,
lastName, lastName,
...@@ -136,23 +135,35 @@ export const JWTProvider = ({ children }: { children: React.ReactElement }) => { ...@@ -136,23 +135,35 @@ export const JWTProvider = ({ children }: { children: React.ReactElement }) => {
confirmPassword, confirmPassword,
type: "member" type: "member"
}); });
let users = response.data;
const user = response.data.result;
if (window.localStorage.getItem('users') !== undefined && window.localStorage.getItem('users') !== null) { if (window.localStorage.getItem('users') !== undefined && window.localStorage.getItem('users') !== null) {
const localUsers = window.localStorage.getItem('users'); const localUsers = window.localStorage.getItem('users');
users = [ const users = [
...JSON.parse(localUsers!), ...JSON.parse(localUsers!),
{ {
id, id: user._id,
email, email: user.email,
password, password: user.password,
name: `${firstName} ${lastName}` 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 = () => { const logout = () => {
setSession(null); setSession(null);
dispatch({ type: LOGOUT }); 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