• RE: Redirect to login

    @baris That's it. Worked like a charm. Thanks!

    posted in Plugin Development
  • RE: Redirect to login

    I also tried to use the helper function notAllowed, but I get the same result. Redirects to /login but get errors in the log that data is undefined and there is no catch().

    library.checkLoginStatus = async (data) => {
    	if (data.req.loggedIn ||
    		allowedUrls(data.req.url)
    	) {
    		return data;
    	}
    	return Helpers.notAllowed(data.req, data.res);
    };
    
    posted in Plugin Development
  • RE: Redirect to login

    Seems like reverting to callbacks resolves it. I really wanted this to work with async/await, since callbacks will sooner or later be phased out I guess.

    library.checkLoginStatus = (data, callback) => {
    	if (data.req.loggedIn ||
    		allowedUrls(data.req.url)
    	) {
    		callback(null, data);
    	} else {
    		Helpers.redirect(data.res, '/login');
    	}
    };
    
    posted in Plugin Development
  • RE: Redirect to login

    Though this works, it also redirects every call for assets (images, stylesheets etc). So I get a site without CSS. ๐Ÿ˜„

    Maybe another hook is more appropriate?

    I also have another function that redirects to the profile page if some information is not properly filled in.

    So the overarching question is not to lock people out, it's more about how to divert a user based on some conditions. For instance, we have to require the users full name, so if it's not filled out, they get redirected to their profile edit page and asked to fill it in.

    EDIT: I forgot to tag you @baris.

    posted in Plugin Development
  • Redirect to login

    I have been having some issues since NodeBB went all in on async/await. I have a private forum so I need to redirect to /login if the visitor isn't logged in.

    What worked before was a library function listening to filter:middleware.render, and then:

    library.checkLoginStatus = async (data) => {
    
    	if (data.req.loggedIn ||
    			allowedUrls(data.req.url)
    	) {
    		return data;
    	}
    	return Helpers.redirect(data.res, '/login');
    };
    

    allowedUrls is a function that just checks the requested url against a list of allowed ones (like /login, /email/unsubscribe and /register).

    Everything worked great but now I'm upgraded to 1.16.x.

    The issue I'm having is that there are other functions that tails this one listening to the same hook. So my question is if I can interrupt that flow somehow on redirect. Or maybe there's an even better solution, but it needs to be forum wide. The tailing functions get undefined passed in so everything breaks. The weird thing is that everything seems to work, and it semi silently drops the error. But I don't want a bunch of error logs cluttering things up.

    I know NodeBB is meant to be open and all, but in this case I need to lock it down until someone has registered. I built this functionality when on 1.12 I think so something else might be a better option.

    I'm turning to you community.

    posted in Plugin Development
  • RE: Difference between templateValues and templateData

    Yep, I see the issue. I'm not looking to push any changes. It was more out of curiosity on why there are several different names within essentially the same function.

    posted in Plugin Development
  • RE: Difference between templateValues and templateData

    Yeah, I guess my line of thinking is; why not just have templateValues and templateData on initial render and then templateDataon page render? It just feels a bit confusing with these different signatures and names.

    So, what is data used for when header is rendered? Is it even used? And if not, why not just use templateData on all of them with things related to their function?

    templateData on header hook is to render header.
    templateData on page hook is to render page.
    templateData on footer hook is to render footer.

    I'm guessing there are cases where it's useful for data to be passed along the ride, but they're already treated as different parts, so maybe it's just easier to separate them entirely.

    posted in Plugin Development
  • Difference between templateValues and templateData

    Hi!
    What's the difference between templateValues (tV) and templateData (tD)?

    I know we get tD from a template hook and tV from a header hook, but we also get data from the header hook, which contains the dame data as in tD?

    Hook data object keys in the two cases:

    • [ 'req', 'res', 'templateValues', 'data' ] from header hook.
    • [ 'req', 'res', 'templateData' ] from template hook.

    So this might not be a technical question at all. I'm just wondering what the naming is meant to be. Maybe someone can shed some light on this, perhaps simple question?

    For instance, if data in header hook is the same as tD in template hook, why is it not just called templateData instead, to avoid confusion?

    I guess a header hook is only fired on initial render and not when the user navigates around, as is the case with a template hook.

    Also, when for filter:middleware.renderFooter is fired, only tV is present and not data?

    posted in Plugin Development
  • Hide category from feeds

    Is there some way to hide all topics within a category from all feeds (recent, popular, new, the digest)?

    I need the topics to be accessible (and usable) to all users directly, but not searchable or showing up at random.

    posted in Plugin Development
  • RE: Send invite without a user

    Thank you for the response @gotwf!

    The issue is that I cannot delete an invite if I leave the inviter uid blank. I would think that an error would've been sent if this would cause problems. I have added a field in my plugin that will let admins select who will work as the inviter. in my case it's a system user, like no_reply@service...

    The sender is a no-person email so that's not the issue. The issue is that the invite needs to (in the system) be sent my a user. Which doesn't make sense in my opinion. It's great if an admin sends an invite, but why prevent me from deleting an invite that doesn't have an error?

    posted in Plugin Development