Depending on the plugin hook, the uid is included in the payload.
Forcing UID value
-
Is not possible force the uid value on user.create ? i'm doing this but it look don't work :
if (!_uid) { user.create({ uid: userObj.uid, username: userObj.display, email: userObj.email }, callback);
-
It's not possible right now,
user.create
generates the next available uid and uses it. Any particular reason you want to overwrite it? -
i've made a fork of nodebb-plugin-login-mysite ( https://github.com/SimosNap/nodebb-plugin-login-anope ) to login to the forum using IRC anope account. On IRC users can change both username and email so UID is the only things i can refer for account updates
-
@baris do you have any suggestions for my purpose ?
-
I'd recommend against updating the uid, but letting NodeBB handle uids on its own. If you want to save the id of the user, then you should save it as a different value into the user hash instead...
-
@julian it's only some days i'm using nodebb and i'm new to redis too, do you mean create a new field in user table ? If so how do ?
-
In the fork of your login plugin, you should be able to save the remoteId into the user hash on the
user.create
call. -
@julian Pheraps i miss something , i don't see an user hash field in user table :
[ { uid: 4,
username: 'antani',
userslug: 'antani',
picture: '',
status: 'online',
postcount: 0,
reputation: 0,
'email:confirmed': 0,
lastonline: 1542925209728,
flags: null,
banned: 0,
'banned:expire': 0,
joindate: 1542925209728,
uploadedpicture: undefined,
'icon:text': 'A',
'icon:bgColor': '#2196f3',
joindateISO: '2018-11-22T22:20:09.728Z',
lastonlineISO: '2018-11-22T22:20:09.728Z',
banned_until: 0,
banned_until_readable: 'Not Banned',
administrator: false } ] -
@Simos what you just posted is what Julian referred to by "user hash". He was saying "hash table" otherwise called an object or a dictionary.
-
@PitaJ i've try to add the remoteid on user.create :
console.log(_uid); if (!_uid) { user.create({ remoteid: userObj.uid, username: userObj.display, email: userObj.email }, callback); } else { callback(null, _uid) }
I suppose it don't add the remoteid value because remoteid field doesn't exist right ?
-
You will need a plugin to save the
remoteid
into the user hash, so in your plugin listen for'filter:user.create'
here is how it should look.myPlugin.filterUserCreate = function (hookData, callback) { hookData.user.remoteid = hookData.data.remoteid; callback(null, hookData); };
-
Thanks ! Why i can get it with user.getUserFields but not with user.getUser ?
-
Is there any existent function to get uid having a field value ? (in my case external uid)
-
.getUserField()
should work, though you will need to implement the whitelist as @baris has mentioned. -
@julian it look getUserField() need nodebb uid i've to get userdata having the remoteid (the customfield i've added)
plugin.filterUserCreate = function (data, callback) {
data.user.auid = data.data.auid;
callback(null, data);
};plugin.whitelistFields = function(data, callback) {
data.whitelist.push('auid');
callback(null, data);
}; -
Yeah you'll have to save a map of auids to uids in the database.
-
@PitaJ is there any example of code for this ?
-
@Simos what have you tried so far?
-
@julian I've try only user.getUserDataByField function
than i've discovered is limited.
-
Yes, you can use that method. You just need to create a plugin hook listener to the whitelist hook @baris mentioned, so you can add the remoteId to the whitelisted fields.