How to check if a visitor is registered or a guest?
Solved
Plugin Development
-
@baris said:
You can use req.uid to check if user is logged in or not.
Its giving me error: req is not defined.
Note: I am currently testing the plugin under my nodebb 1.0.0 version localhost. But my actual site is running on 0.9.4 version where i'll be adding this plugin.
-
-
@Nisthar
What about this http://nodebb-francais.readthedocs.org/projects/nodebb/en/latest/plugins/create.htmlvar cls = module.parent.require('./middleware/cls'); // require cls once in your plugin. var MyPlugin = { myMethod: function(postData, callback) { var req = cls.get('http').req; // current http request object. var res = cls.get('http').res; // current http response object. var uid = req.user.uid; // current user id // ... }, // let's say this one occurs on a websocket event, myOtherMethod: function(somethingData) { var socket = cls.get('ws').socket; // current socket object. var uid = socket.uid; // current user id, if available var payload = cls.get('ws').payload; // socket payload data, if available var event = cls.get('ws').event; // socket last event, if available // ... } };
-
@qgp9 said:
@Nisthar
What about this http://nodebb-francais.readthedocs.org/projects/nodebb/en/latest/plugins/create.htmlvar cls = module.parent.require('./middleware/cls'); // require cls once in your plugin. var MyPlugin = { myMethod: function(postData, callback) { var req = cls.get('http').req; // current http request object. var res = cls.get('http').res; // current http response object. var uid = req.user.uid; // current user id // ... }, // let's say this one occurs on a websocket event, myOtherMethod: function(somethingData) { var socket = cls.get('ws').socket; // current socket object. var uid = socket.uid; // current user id, if available var payload = cls.get('ws').payload; // socket payload data, if available var event = cls.get('ws').event; // socket last event, if available // ... } };
Its giving error module not found require('./middleware/cls') last time i checked.
-
I'm not sure why that appears on the docs. That change has not been added into the code yet.
https://github.com/NodeBB/NodeBB/pull/4162
Copyright © 2024 NodeBB | Contributors