Email missing while API create user
-
Hello,
I use the v3 API and Bearer Token to create new users, but it doesn't work anymore. I don't know why and don't know how to debug it.The user is created well but the email doesn't seem to update, same when I use the email change API.
Heres the Postman:
Also used this API route to direct email change: https://github.com/NodeBB/NodeBB/blob/master/src/routes/write/users.js#L56
it says ok but nothing changes.
-
That route should work if the calling user is a privileged user like an admin and
skipConfirmation
is passed in req.bodyusersAPI.addEmail = async (caller, { email, skipConfirmation, uid }) => { const isSelf = parseInt(caller.uid, 10) === parseInt(uid, 10); const canEdit = await privileges.users.canEdit(caller.uid, uid); if (skipConfirmation && canEdit && !isSelf) { if (!email.length) { await user.email.remove(uid); } else { if (!await user.email.available(email)) { throw new Error('[[error:email-taken]]'); } await user.setUserField(uid, 'email', email); await user.email.confirmByUid(uid, caller.uid); } } else { await usersAPI.update(caller, { uid, email }); } return await db.getSortedSetRangeByScore('email:uid', 0, 500, uid, uid); };
-
@baris
Thanks a lot baris, it's working now, don't know why it used to work until today.Is there any way to bypass that confirmation? And why on the documentation it says that we can add email using this route : https://try.nodebb.org/api/v3/users/ and nothing happens? should I tick somewhere in the settings?
-
You can read more info here https://community.nodebb.org/topic/16962/all-about-emails-and-how-they-re-used-in-nodebb, tldr version is passing in email to user.create only sends a confirmation email to that email and doesn't set the email to the user account. Only when the user clicks the link in the confirmation email it is set into the user account.
-