obtain roles from user returning empty object

Viewed 13

i am trying to get roles from user, but got empty object instead

export async function resetPassword(req, res) {
    const { id } = req.user;        
  
    try {    
      const loggedInUser = await User.where('id', id).fetch({withRelated: ['roles']});
  
      if (!loggedInUser) {      
        return res.status(HttpStatus.NOT_FOUND).json({
          message: 'User not found',
        });
      }
            
      const usersRoles = loggedInUser.roles;
      
      return res.json({
        test: usersRoles
      });    
        
    } catch (err) {
      Logger.error(err.message);
      return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
        message: err.message,
      });
    }
  }

enter image description here

this is the user object

enter image description here

how to access the roles data, please help?

0 Answers
Related