Programatically create users



  • Hello.

    I have a web application with a local login and registration system using email and password.

    I want to programatically create a forum account upon registering for the web application, using the same email and password.

    Is there a way to do this yet or no? I don't mind writing a plugin, but I want to make sure there is no existing way to do this.


  • Community Rep

    There are multiple ways depending on your needs. You probably want nodebb-plugin-session-sharing. This plugin reads a cookie from your app, and when a user logged into your app visits the forum, will create their account and log them in. It can also redirect guests to your apps page, and sign users out when they log out of your app.



  • @yariplus Thanks I will check it out.



  • @yariplus Do you know of a way to just create the users one time? I see the createUser function in nodebb and I'll probably write a plugin to use that, unless you know of someone who has done this already.


  • Community Rep

    @biz That's probably the best way. Any one of the import plugins should have all the methods you need in it already, and you can just add the accounts manually or read from your db etc.


  • Admin

    @biz @yariplus Either write a custom plugin to hook into the createUser method (actually, it's User.create...), or use nodebb-plugin-write-api and make a POST to /api/v1/users to create a new user.

    The latter is likely easier to do :smile:



  • @julian Oh definitely, will do. Thanks.


Log in to reply
 

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.