diff --git a/IHP/AuthSupport/Lockable.hs b/IHP/AuthSupport/Lockable.hs index f27a98ba1..3e515661c 100644 --- a/IHP/AuthSupport/Lockable.hs +++ b/IHP/AuthSupport/Lockable.hs @@ -15,8 +15,11 @@ lockDuration = let timeInSecs = 60 * 60 in secondsToNominalDiffTime timeInSecs isLocked :: forall user. (HasField "lockedAt" user (Maybe UTCTime)) => user -> IO Bool isLocked user = do now <- getCurrentTime - let currentLockedAt :: Maybe UTCTime = getField @"lockedAt" user - pure $! case currentLockedAt of + pure (isLocked' now user) + +isLocked' :: forall user. (HasField "lockedAt" user (Maybe UTCTime)) => UTCTime -> user -> Bool +isLocked' now user = + case getField @"lockedAt" user of Just lockedAt -> let diff = diffUTCTime now lockedAt in diff < lockDuration