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" })
......
...@@ -16,8 +16,7 @@ const userSchema = mongoose.Schema({ ...@@ -16,8 +16,7 @@ const userSchema = mongoose.Schema({
}, },
contactNumber: { contactNumber: {
type: String, type: String,
required: true, required: true,
unique: true
}, },
password: { password: {
type: String, type: String,
......
...@@ -125,9 +125,8 @@ export const JWTProvider = ({ children }: { children: React.ReactElement }) => { ...@@ -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) => { 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,
email, email,
...@@ -135,24 +134,36 @@ export const JWTProvider = ({ children }: { children: React.ReactElement }) => { ...@@ -135,24 +134,36 @@ export const JWTProvider = ({ children }: { children: React.ReactElement }) => {
password, password,
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