platform/lib/middleware/require_auth.dart

13 lines
367 B
Dart
Raw Normal View History

2016-05-03 04:13:19 +00:00
part of angel_auth;
/// Restricts access to a resource via authentication.
Future<bool> requireAuth(RequestContext req, ResponseContext res,
{bool throws: true}) async {
if (req.session.containsKey('userId'))
return true;
2016-05-09 20:47:28 +00:00
else if (throws) {
res.status(HttpStatus.UNAUTHORIZED);
2016-07-03 23:36:41 +00:00
throw new AngelHttpException.Forbidden();
2016-05-09 20:47:28 +00:00
}
2016-05-03 04:13:19 +00:00
else return false;
}