Solved Get req username in server-side


  • Hi,
    I don't know to get the username of request sender
    There is req.uid in RouteHelpers, but without req.username.
    Can render temp with username?
    Thank you!

  • NodeBB

    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') })
        })
    }
    
  • NodeBB

    You need to get the username with await user.getUserField(req.uid, 'username');


  • @baris the problem is: if I use with await - then route not work
    I tried

    init: 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?

  • NodeBB

    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') })
        })
    }
    
  • Topic has been marked as a question  Y Yehonatan Albert 
  • Topic has been marked as solved  Y Yehonatan Albert 

Suggested Topics

  • 4
  • 2
  • 1
  • 3
  • 2
| |