diff --git a/api/src/controllers/userController.js b/api/src/controllers/userController.js index 4a23de1fd..f4e72bdfd 100644 --- a/api/src/controllers/userController.js +++ b/api/src/controllers/userController.js @@ -111,11 +111,11 @@ const localAuth = async (name, password) => { // @access Public const registerUser = async (req, res) => { try { - const { name, password, id } = req.body + const { name, password, id, email } = req.body if (process.env.AUTH_METHOD === 'cognito') { const data = await db.User.findOne({ where: { userID: id } }) if (!data) { - const user = await db.User.create({ userID: id, isLocalAuth: false, lastLogin: new Date(), numberOfVisit: 0 }) + const user = await db.User.create({ email, userID: id, isLocalAuth: false, lastLogin: new Date(), numberOfVisit: 0 }) if (user && await subscribeCommunity(user)) { res.status(201).send('SUCCESS') } @@ -136,7 +136,7 @@ const registerLocal = async (name, password, res) => { if (userExists) { return res.json({ message: 'Users already Exists !!!' }).status(400) } const newUser = await db.sequelize.transaction(async (t) => { const user = await db.LocalAuth.create({ username: name, password: password }, { transaction: t }) - return await db.User.create({ userID: user.id, isLocalAuth: true, lastLogin: new Date(), numberOfVisit: 0 }, { transaction: t }) + return await db.User.create({ email: name, userID: user.id, isLocalAuth: true, lastLogin: new Date(), numberOfVisit: 0 }, { transaction: t }) }) if (newUser && await subscribeCommunity(newUser)) { res.status(201).json({ diff --git a/src/actions/userAction.js b/src/actions/userAction.js index a89269810..cc6f03f85 100644 --- a/src/actions/userAction.js +++ b/src/actions/userAction.js @@ -113,12 +113,12 @@ export const register = (name, password) => async (dispatch) => { username: name, password, attributes: { - email: null + email: name } }) const response = await Auth.signIn(name, password) userdata = { token: response?.signInUserSession?.idToken?.jwtToken, id: response?.attributes?.sub || '' } - const { data } = await postApi(dispatch, `${process.env.REACT_APP_API_BASE_URL}/api/users`, { id: userdata.id }, { + const { data } = await postApi(dispatch, `${process.env.REACT_APP_API_BASE_URL}/api/users`, { id: userdata.id, email: name }, { headers: { Authorization: 'Bearer ' + userdata.token } @@ -213,7 +213,7 @@ export const checkAndUpdateToken = () => async (dispatch) => { } }).catch((data) => { return tokenFailure(dispatch, 'Unauthorized') - /*const message = data.response && data.response.data.name ? data.response.data.name : data.message + /* const message = data.response && data.response.data.name ? data.response.data.name : data.message if (message === 'TokenExpired') { if (process.env.REACT_APP_AUTH_METHOD === 'cognito') { Auth.currentSession().then((res) => { @@ -242,7 +242,7 @@ export const checkAndUpdateToken = () => async (dispatch) => { } } else { return tokenFailure(dispatch, 'Unauthorized') - }*/ + } */ }) } diff --git a/src/components/signInSignUp/SignIn.jsx b/src/components/signInSignUp/SignIn.jsx index 044b9826f..4a2c0b9b0 100644 --- a/src/components/signInSignUp/SignIn.jsx +++ b/src/components/signInSignUp/SignIn.jsx @@ -117,14 +117,18 @@ const SignIn = () => { {error &&
{error}
} {
{error &&
{error}
} { ref={regi({ required: { value: true, - message: 'You must enter username' + message: 'You must enter email' + }, + pattern: { + value: /\S+@\S+\.\S+/, + message: 'You must enter valid email' } })} errors={errors} diff --git a/src/screens/forgotPassword/ForgotPassword.jsx b/src/screens/forgotPassword/ForgotPassword.jsx index 51a791051..743f214f6 100644 --- a/src/screens/forgotPassword/ForgotPassword.jsx +++ b/src/screens/forgotPassword/ForgotPassword.jsx @@ -76,14 +76,18 @@ const ForgotPassword = () => { {resendErr &&
{resendErr}
} {message &&
{message}
}