From be716378f08b48045124acb8b7fb5d2779fb907a Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Fri, 2 Dec 2022 14:43:52 -0600 Subject: [PATCH] Fix issue of multiple auth calls from WooCommerce --- src/ZGoBackend.hs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index 0521464..1edac81 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -644,14 +644,26 @@ routes pipe config = do , "message" .= ("Authorized!" :: String) ]) else do - status accepted202 - Web.Scotty.json - (object - [ "authorized" .= False - , "message" .= - ("ZGo shop already linked to" <> - fromMaybe "" (w_url c)) - ]) + if (E.decodeUtf8With lenientDecode . + B64.decodeLenient . C.pack . T.unpack) + siteurl == + fromMaybe "" (w_url c) + then do + status ok200 + Web.Scotty.json + (object + [ "authorized" .= True + , "message" .= ("Already authorized." :: String) + ]) + else do + status accepted202 + Web.Scotty.json + (object + [ "authorized" .= False + , "message" .= + ("ZGo shop already linked to " <> + fromMaybe "" (w_url c)) + ]) else do status accepted202 Web.Scotty.json