platform/lib/middleware/require_auth.dart
2016-07-03 19:36:41 -04:00

13 lines
No EOL
367 B
Dart

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;
else if (throws) {
res.status(HttpStatus.UNAUTHORIZED);
throw new AngelHttpException.Forbidden();
}
else return false;
}