owner method

Future<Response?> owner(
  1. Request req,
  2. dynamic user, {
  3. String idParam = 'user_id',
})

Implementation

Future<Response?> owner(Request req, user,
    {String idParam = 'user_id'}) async {
  if (user == null) {
    return await HttpResponseSender.sendError(
        req,
        UnauthorizedException(null, 'NOT_SIGNED',
                'User must be signed in to perform this operation')
            .withStatus(401));
  } else {
    var userId = req.params[idParam] ?? req.url.queryParameters[idParam];
    if (user.user_id != userId) {
      return await HttpResponseSender.sendError(
          req,
          UnauthorizedException(null, 'FORBIDDEN',
                  'Only data owner can perform this operation')
              .withStatus(403));
    }
  }
}