Skip to content

Commit c675a83

Browse files
committed
small code cleanup
1 parent 7149c51 commit c675a83

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/PostgREST/Auth/JwtCache.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,43 +59,43 @@ lookupJwtCache jwtCacheState token parseJwt utc = do
5959
authResult <- parseJwt
6060

6161
case authResult of
62-
Right res -> do
62+
Right result -> do
6363
-- insert token -> update cache -> return token
64-
let jwtCache'' = C.insert token res jwtCache'
64+
let jwtCache'' = C.insert token result jwtCache'
6565
I.writeIORef jwtCacheIORef jwtCache''
66-
return $ Right res
66+
return $ Right result
6767
Left e -> do
6868
-- update cache after lookup -> return error
6969
I.writeIORef jwtCacheIORef jwtCache'
7070
return $ Left e
7171

72-
Just res -> -- CACHE HIT
72+
Just result -> -- CACHE HIT
7373

7474
-- For cache hit, we get the result from cache, we check the
7575
-- exp claim. If it expired, we delete it from cache and parse
7676
-- the jwt. Otherwise, the hit result is valid, so we return it
7777

78-
if isExpClaimExpired res utc then do
78+
if isExpClaimExpired result utc then do
7979
-- delete token -> update cache -> parse token
8080
let (jwtCache'',_) = C.delete token jwtCache'
8181
I.writeIORef jwtCacheIORef jwtCache''
8282
parseJwt
8383
else do
8484
-- update cache afte lookup -> return result
8585
I.writeIORef jwtCacheIORef jwtCache'
86-
return $ Right res
86+
return $ Right result
8787

8888

8989
type Expired = Bool
9090

9191
-- | Check if exp claim is expired when looked up from cache
9292
isExpClaimExpired :: AuthResult -> UTCTime -> Expired
93-
isExpClaimExpired res utc =
93+
isExpClaimExpired result utc =
9494
case expireJSON of
9595
Nothing -> False -- if exp not present then it is valid
9696
Just (JSON.Number expiredAt) -> (sciToInt expiredAt - now) < 0
9797
Just _ -> False -- if exp is not a number then valid
9898
where
99-
expireJSON = KM.lookup "exp" (authClaims res)
99+
expireJSON = KM.lookup "exp" (authClaims result)
100100
now = (floor . nominalDiffTimeToSeconds . utcTimeToPOSIXSeconds) utc :: Int
101101
sciToInt = fromMaybe 0 . Sci.toBoundedInteger

0 commit comments

Comments
 (0)