Get req username in server-side
Solved
Plugin Development
-
Hi,
I don't know to get the username of request sender
There isreq.uid
in RouteHelpers, but withoutreq.username
.
Can render temp with username?
Thank you! -
You need to make your controller async for it to work.
init: async params => { RouteHelpers.setupAdminPageRoute(params.router, '/admin/plugins/myplugin', params.middleware, [], async (req, res) => { res.render('admin/plugins/myplugin', { username: await User.getUserField(req.uid, 'username') }) }) }
-
@baris the problem is: if I use with await - then route not work
I triedinit: async params => { RouteHelpers.setupAdminPageRoute(params.router, '/admin/plugins/myplugin', params.middleware, [], (req, res) => { res.render('admin/plugins/myplugin', { username: await User.getUserField(req.uid, 'username') }) }) }
or
init: async params => { User.getUserField(req.uid, 'username', username => { RouteHelpers.setupAdminPageRoute(params.router, '/admin/plugins/myplugin', params.middleware, [], (req, res) => { res.render('admin/plugins/myplugin', { username: username }) }) }) }
The admin route waiting and not load..
What you think? -
You need to make your controller async for it to work.
init: async params => { RouteHelpers.setupAdminPageRoute(params.router, '/admin/plugins/myplugin', params.middleware, [], async (req, res) => { res.render('admin/plugins/myplugin', { username: await User.getUserField(req.uid, 'username') }) }) }
-
-
Copyright © 2024 NodeBB | Contributors