diff options
Diffstat (limited to 'website/sandbox/learnpianochords/src/server/Main.hs')
-rw-r--r-- | website/sandbox/learnpianochords/src/server/Main.hs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/website/sandbox/learnpianochords/src/server/Main.hs b/website/sandbox/learnpianochords/src/server/Main.hs index 2d7120bd614c..67f9fd3aca59 100644 --- a/website/sandbox/learnpianochords/src/server/Main.hs +++ b/website/sandbox/learnpianochords/src/server/Main.hs @@ -7,10 +7,14 @@ module Main where import Servant import API import Control.Monad.IO.Class (liftIO) +import GoogleSignIn (EncodedJWT(..), ValidationResult(..)) +import Data.String.Conversions (cs) +import Utils import qualified Network.Wai.Handler.Warp as Warp import qualified Network.Wai.Middleware.Cors as Cors import qualified Types as T +import qualified GoogleSignIn -------------------------------------------------------------------------------- server :: Server API @@ -18,8 +22,13 @@ server = verifyGoogleSignIn where verifyGoogleSignIn :: T.VerifyGoogleSignInRequest -> Handler NoContent verifyGoogleSignIn T.VerifyGoogleSignInRequest{..} = do - liftIO $ putStrLn $ "Received: " ++ idToken - pure NoContent + validationResult <- liftIO $ GoogleSignIn.validateJWT False (EncodedJWT idToken) + case validationResult of + Valid _ -> do + liftIO $ putStrLn "Sign-in valid! Let's create a session" + pure NoContent + err -> do + throwError err401 { errBody = err |> GoogleSignIn.explainResult |> cs } main :: IO () main = do |