@julian I will give it a try, Thanks so much.
Solved How to check if a visitor is registered or a guest?
-
How can i check if the visitor is a registered user or a guest ?
I am looking for server side solution for my plugin
-
What is your git hash? Does it happen on this forum?
-
-
-
-
You can use req.uid to check if user is logged in or not.
-
@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.
-
@baris said:
You can use req.uid to check if user is logged in or not.
Do i need to use cls middleware? I tried using it. But its too giving me errors.
-
@Nisthar
You may needuser = module.parent.require('./user')
.nodebb-plugin-composer-default will be good example for you.
-
@qgp9 said:
@Nisthar
You may needuser = module.parent.require('./user')
.nodebb-plugin-composer-default will be good example for you.
But i think there is no method to check if the user is a registered member or non-member in it
-
@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