Skip to content

Commit

Permalink
emailOriginal option
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmeeusen committed Jun 16, 2022
1 parent 3a715f2 commit d0518de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions api-lib/db/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ export async function updateUserById(db, id, data) {

export async function insertUser(
db,
{ email, originalPassword, bio = '', name, profilePicture, username }
{ emailOriginal, email, originalPassword, bio = '', name, profilePicture, username }
) {
const user = {
emailOriginal,
email,
emailVerified: false,
profilePicture,
email,
name,
username,
bio,
Expand Down Expand Up @@ -98,7 +99,8 @@ export async function UNSAFE_updateUserPassword(db, id, newPassword) {
export function dbProjectionUsers(prefix = '') {
return {
[`${prefix}password`]: 0,
[`${prefix}emailOriginal`]: 0,
[`${prefix}email`]: 0,
[`${prefix}emailVerified`]: 0,
};
}
}
5 changes: 5 additions & 0 deletions pages/api/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ handler.post(
const db = await getMongoDb();

let { username, name, email, password } = req.body;
const emailOriginal = email;
username = slugUsername(req.body.username);
email = normalizeEmail(req.body.email);

if (!isEmail(email)) {
res
.status(400)
Expand All @@ -47,13 +49,16 @@ handler.post(
.json({ error: { message: 'The username has already been taken.' } });
return;
}

const user = await insertUser(db, {
emailOriginal,
email,
originalPassword: password,
bio: '',
name,
username,
});

req.logIn(user, (err) => {
if (err) throw err;
res.status(201).json({
Expand Down

0 comments on commit d0518de

Please sign in to comment.