Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

How to load a javascript component only for logged in users? (converse.js xmpp chat)

0 votes
76 views
asked Dec 26, 2017 in Plugins by poVoq
I would like to enable XMPP chat on my Q2A page. I already have a ejabberd server running, so it is only a question of getting a smooth integration with Q2A.

The best option seems to be this:

https://github.com/jcbrand/converse.js/

My idea is that the on-site pop-up chat should only be loaded for logged-in users (ideally getting the user data out of the Q2A database, as this is also where my ejabbered server indirectly gets its login data), and a full page chat with anonymous log-in as a  Q2A page (or maybe one per categrory?).

I guess to really get that working one would need to write a plugin, but is there a easy way I can make sure the javascript for the pop-up chat is only loaded for logged-in users as a start?
Q2A version: 1.8 beta

1 Answer

+1 vote
answered Dec 26, 2017 by pupi1985

As explained in the docs, there is a function to check for a user being logged in or not: qa_is_logged_in(). So all you need to do is:

if (qa_is_logged_in()) {

    // Code to insert your JavaScript

}

...