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 all commits
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
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,
};
}
}
3 changes: 2 additions & 1 deletion page-components/Settings/index.jsx
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ const EmailVerify = ({ user }) => {
<Container flex={1}>
<p>
<strong>Note:</strong> <span>Your email</span> (
<span className={styles.link}>{user.email}</span>) is unverified.
<span className={styles.link}>{user.emailOriginal}</span>) is unverified.
</p>
</Container>
<Spacer size={1} axis="horizontal" />
@@ -204,6 +204,7 @@ export const Settings = () => {
router.replace('/login');
}
}, [router, data, error]);

return (
<Wrapper className={styles.wrapper}>
<Spacer size={2} axis="vertical" />
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({