Set role locally in a tx to ensure it is reset after error
This commit is contained in:
@@ -53,14 +53,14 @@ checkPass :: Text -> Text -> Bool
|
||||
checkPass = (. cs) . validatePassword . cs
|
||||
|
||||
setRole :: Text -> H.Tx P.Postgres s ()
|
||||
setRole role = H.unitEx $ B.Stmt ("set role " <> cs (pgFmtLit role)) V.empty True
|
||||
setRole role = H.unitEx $ B.Stmt ("set local role " <> cs (pgFmtLit role)) V.empty True
|
||||
|
||||
resetRole :: H.Tx P.Postgres s ()
|
||||
resetRole = H.unitEx [H.stmt|reset role|]
|
||||
|
||||
setUserId :: Text -> H.Tx P.Postgres s ()
|
||||
setUserId uid = if uid /= "" then
|
||||
H.unitEx $ B.Stmt ("set user_vars.user_id = " <> cs (pgFmtLit uid)) V.empty True
|
||||
H.unitEx $ B.Stmt ("set local user_vars.user_id = " <> cs (pgFmtLit uid)) V.empty True
|
||||
else
|
||||
resetUserId
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ main = do
|
||||
|
||||
runSettings appSettings $ middle $ \req respond -> do
|
||||
body <- strictRequestBody req
|
||||
resOrError <- liftIO $ H.session pool $ H.tx Nothing $
|
||||
resOrError <- liftIO $ H.session pool $ H.tx (Just (H.ReadUncommitted, Just True)) $
|
||||
authenticated conf (app conf body) req
|
||||
either (respond . errResponse) respond resOrError
|
||||
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ withApp perform = do
|
||||
|
||||
perform $ middle $ \req resp -> do
|
||||
body <- strictRequestBody req
|
||||
result <- liftIO $ H.session pool $ H.tx Nothing
|
||||
result <- liftIO $ H.session pool $ H.tx (Just (H.ReadUncommitted, Just True))
|
||||
$ authenticated cfg (app cfg body) req
|
||||
either (resp . errResponse) resp result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user