Removes 'Prefer: return=jwt' header and chooses jwt return based on function type

This commit is contained in:
Diogo Biazus
2015-10-20 01:03:11 -04:00
parent 2ea7bc29c6
commit 044e3865ac
2 changed files with 20 additions and 5 deletions
+2 -1
View File
@@ -175,9 +175,10 @@ app dbstructure conf reqBody req =
let call = B.Stmt "select " V.empty True <>
asJson (callProc qi $ fromMaybe M.empty (decode reqBody))
bodyJson :: Maybe (Identity Value) <- H.maybeEx call
returnJWT <- doesProcReturnJWT schema proc
return $ responseLBS status200 [jsonH]
(let body = fromMaybe emptyArray $ runIdentity <$> bodyJson in
if hasPrefer "return=jwt"
if returnJWT
then "{\"token\":\"" <> cs (tokenJWT jwtSecret body) <> "\"}"
else cs $ encode body)
else return $ responseLBS status404 [] ""