Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emailOriginal #146

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
emailOriginal option
danielmeeusen committed Jun 16, 2022
commit d0518de82c6e7ba48ad494a40ce74d4993bb9239
8 changes: 5 additions & 3 deletions api-lib/db/user.js
Original file line number Diff line number Diff line change
@@ -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,
@@ -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
@@ -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)
@@ -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({