Skip to content

Commit 969367f

Browse files
committed
Send 3001 as a connection termination code when the JWT expires
1 parent ac75718 commit 969367f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/PostgresWebsockets.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ postgresWsMiddleware =
4747
compose = (.) . (.) . (.) . (.) . (.)
4848

4949
-- private functions
50+
jwtExpirationStatusCode :: Word16
51+
jwtExpirationStatusCode = 3001
5052

5153
-- when the websocket is closed a ConnectionClosed Exception is triggered
5254
-- this kills all children and frees resources for us
@@ -73,7 +75,7 @@ wsApp getTime dbChannel secret pool multi pendingConn =
7375
WS.withPingThread conn 30 (pure ()) $ do
7476
case M.lookup "exp" validClaims of
7577
Just (A.Number expClaim) -> do
76-
connectionExpirer <- newAlarmClock $ const (WS.sendClose conn ("JWT expired" :: ByteString))
78+
connectionExpirer <- newAlarmClock $ const (WS.sendCloseCode conn jwtExpirationStatusCode ("JWT expired" :: ByteString))
7779
setAlarm connectionExpirer (posixSecondsToUTCTime $ realToFrac expClaim)
7880
Just _ -> pure ()
7981
Nothing -> pure ()

0 commit comments

Comments
 (0)