verifySession function

Future? verifySession(
  1. ExpressRequest req,
  2. ExpressResponse res, {
  3. String authorizationKey = 'id',
  4. bool throwOnFail = true,
})

Implementation

Future<dynamic>? verifySession(ExpressRequest req, ExpressResponse res,
    {String authorizationKey = 'id', bool throwOnFail = true}) async {
  final Session session = await req.session;
  final String? authId = session[authorizationKey];

  if (authId is! String || authId.isEmpty) {
    if (throwOnFail) {
      return null;
      // throw res.statusCode(HttpStatus.unauthorized).send('data');
    } else {
      return null;
    }
  }

  return authId;
}