authenticate ::
     ByteString -> BackendConf -> AuthUser -> ByteString -> W.Application
authenticate key be user url _req resp = do
  now <- epochTime
  let domain = pack <$> beCookieDomain be
      expiry = now + CTime (beCookieMaxAge be)
      authCookie = AuthCookie {acUser = user, acExpiry = expiry}
      cookie =
        WC.def
          { WC.setCookieName = pack $ beCookieName be
          , WC.setCookieHttpOnly = True
          , WC.setCookiePath = Just "/"
          , WC.setCookieSameSite = Nothing
          , WC.setCookieSecure = True
          , WC.setCookieValue = cookieEncode key authCookie
          , WC.setCookieDomain = domain
          , WC.setCookieExpires =
              Just . posixSecondsToUTCTime . realToFrac $ expiry
          }
  resp $
    W.responseLBS
      seeOther303
      [ (hLocation, url)
      , ("Set-Cookie", toByteString $ WC.renderSetCookie cookie)
      ]
      ""
authenticate ::
     ByteString -> BackendConf -> AuthUser -> ByteString -> W.Application
authenticate key be user url _req resp = do
  now <- epochTime
  let domain = pack <$> beCookieDomain be
      expiry = now + CTime (beCookieMaxAge be)
      authCookie = AuthCookie {acUser = user, acExpiry = expiry}
      cookie =
        WC.def
          { WC.setCookieName = pack $ beCookieName be
          , WC.setCookieHttpOnly = True
          , WC.setCookiePath = Just "/"
          , WC.setCookieSameSite = Nothing
          , WC.setCookieSecure = True
          , WC.setCookieValue = cookieEncode key authCookie
          , WC.setCookieDomain = domain
          , WC.setCookieExpires =
              Just . posixSecondsToUTCTime . realToFrac $ expiry
          }
  resp $
    W.responseLBS
      seeOther303
      [ (hLocation, url)
      , ("Set-Cookie", toByteString $ WC.renderSetCookie cookie)
      ]
      ""
authenticate key be user url _req resp = do
  now <- epochTime
  let domain = pack <$> beCookieDomain be
      expiry = now + CTime (beCookieMaxAge be)
      authCookie = AuthCookie {acUser = user, acExpiry = expiry}
      cookie =
        WC.def
          { WC.setCookieName = pack $ beCookieName be
          , WC.setCookieHttpOnly = True
          , WC.setCookiePath = Just "/"
          , WC.setCookieSameSite = Nothing
          , WC.setCookieSecure = True
          , WC.setCookieValue = cookieEncode key authCookie
          , WC.setCookieDomain = domain
          , WC.setCookieExpires =
              Just . posixSecondsToUTCTime . realToFrac $ expiry
          }
  resp $
    W.responseLBS
      seeOther303
      [ (hLocation, url)
      , ("Set-Cookie", toByteString $ WC.renderSetCookie cookie)
      ]
      ""