• RE: Use method from library.js in main.js ( static js file )

    I don't believe you can do that since what you're asking for is using server side code on the client. To do that, the entire stack would need to be available on the client and everything it does. Basically running NodeBB on the client.

    What you could do is set up your own socket and return the desired data that way.

    In your library.js file:

    const pluginSockets = require.main.require('./src/socket.io/plugins');
    
    // This will add to the sockets object used by NodeBB core
    pluginSockets.customFunc = ((socket, dataDoToFetch, done) => {
    	const response = 'This response is only a string but it can be whatever you want';
    	done(null, response);
    });
    

    Then client side:

    socket.emit('plugins.customFunc', dataDoToFetch, (err, data) => {
    	if (err) console.log('My socket customFunc', err, data);
    	else console.log('Do stuff with this', data);
    });
    

    I cannot guarantee that this will work out of the box since my setup involves a bit more complexity, but this is the basic idea. Give it a shot!

    posted in Plugin Development
  • Cached scripts

    Hi all!
    I've run into an issue that when I deploy a new version of my theme/plugin, most users don't get any changes done until they do a hard refresh. This only seems to affect the client side Javascript, so everything looks updated, but in reality functionality gets lost.

    Has anyone stumbled upon something similar? Is there a better way to release code?

    The background in this is that I have forked Persona and built upon it, so all changes to the platform is basically in the theme. Is there a way to make sure all clients receive all updates?

    Thanks!

    posted in Plugin Development
  • Adding custom fields to edit.tpl

    Hi all!
    I was wondering if there's a simple way to add my custom fields (from the ns-custom-fields plugin) to the regular edit.tpl. I'm making a private forum aimed at professionals and would really love it if I could have everything in one place.

    What I'm currently looking to add is Company, Title and possible some more in the future.

    An idea I have is to just put them in the available form and then using the custom-fields "API" in the backend (on save) to store them separately.

    Any ideas are welcome.

    Sorry to tag you (@Nicolas, the creator) but I believe you can answer this question quite easily.

    Thanks!

    posted in Plugin Development
  • RE: Referrer doesn't redirect?

    @baris Awesome, thanks a lot!

    posted in Technical Support
  • RE: Referrer doesn't redirect?

    A related question. If I need to redirect the logged in user to their profile because I need them to fill in a field, how would I go about doing that?

    At the moment I catch the hook filter:middleware.render and do a res.redirect('/user/[username]/edit'). It works great on initial render, but when I try to click somewhere the main area just goes blank.

    I believe it has to do with the api call being made to re-render the page. I am not familiar enough with the inner workings to know why this is happening.

    posted in Technical Support
  • RE: Referrer doesn't redirect?

    It receives the referrer but only after the first step, not after GDPR and ToS. I'm running version 1.12.1.

    posted in Technical Support
  • Referrer doesn't redirect?

    Re: Redirect after register/registration

    In my theme I try to accomplish this like so:

    library.redirectAfterRegistration = (data, callback) => {
    	user.getUserData(data.uid, (err, userdata) => {
    		if (err) {
    			return callback(err);
    		}
    		const url = nconf.get('relative_path') + '/user/' + encodeURIComponent(userdata.userslug);
    		data.referrer = url;
    
    		callback(null, data);
    	});
    };
    

    Any idea why it's not working? The referrer looks good '/user/[username]'.

    Screenshot 2019-11-18 at 22.40.23.png

    posted in Technical Support
  • RE: Posted body empty

    When I remove enctype="multipart/form-data" from the form in registerComplete.tpl it works. So this has to do with encryption and maybe that I don't have HTTPS on my local machine. So then my question is, why is this not on the form that transmits the username and password?

    posted in NodeBB Development
  • RE: Posted body empty

    The content I posted is just what it looked like in Firefox, Chrome parses it just fine.

    posted in NodeBB Development
  • Posted body empty

    So I have a weird bug that I'm struggling with. In the registration flow I have GDPR consent activated. When the first step is done, I tick both boxes and proceed. I then get the message that I have not ticked the checkboxes (which I have).

    I checked around the request object and the post body is empty. All data from the previous step is in the session object. I have a dev environment and it works there and the live environment. but not my local machine.

    I have been trying to trace the code, but no luck. The content gets posted, but nothing arrives in authenticationController.registerComplete (req.body).

    Tried in both Chrome and Firefox.

    This is what is put in the headers (Firefox):

    -----------------------------20020895991986255501110031412
    Content-Disposition: form-data; name="gdpr_agree_data"
    
    on
    -----------------------------20020895991986255501110031412
    Content-Disposition: form-data; name="gdpr_agree_email"
    
    on
    -----------------------------20020895991986255501110031412--
    

    Not sure if it's related, but the csrf-token is not the same as in the first registration form.

    Where the interstitials are added src/user/index.js row 335. The data arriving in the callback is userData: {} and formData, which is populated with data from the first step (username etc.).

    posted in NodeBB Development