handle method

  1. @override
Future<DoxResponse> handle(
  1. DoxRequest req,
  2. Next next
)
override

Implementation

@override
Future<DoxResponse> handle(DoxRequest req, Next next) async {
  if (_excluded(req.uri.path)) return next();
  Session session = req.session;
  String method = req.httpRequest.method;
  if (method != 'GET' &&
      method != 'HEAD' &&
      method != 'OPTIONS' &&
      !_same(session.token, _given(req))) {
    throw TokenMismatchException();
  }
  DoxResponse res = await next();
  // read it after the controller: regenerate() makes a new one
  String token = session.token;
  if (req.cookie(cookieName, decrypt: false) != token) {
    SessionConfig config = Dox().config.session;
    res.cookie(
      DoxCookie(
        cookieName,
        token,
        encrypt: false,
        httpOnly: false,
        maxAge: config.lifetime,
        path: config.path,
        domain: config.domain,
        secure: config.secure,
        sameSite: config.sameSite,
      ),
    );
  }
  return res;
}