about summary refs log blame commit diff
path: root/website/sandbox/learnpianochords/src/server/Types.hs
blob: a9e6661f6153bc06dc06a02ab8a2f95d7e9fa6a2 (plain) (tree)
1
2
3
4
5
6
7
8


                                                                                
          
                 
                                          

                                                                                
















                                                                     


                                           
                                                          
                    





                                                 
--------------------------------------------------------------------------------
module Types where
--------------------------------------------------------------------------------
import RIO
import Data.Aeson
import System.Envy (FromEnv, fromEnv, env)
--------------------------------------------------------------------------------

-- | Read from .envrc
data Env = Env
  { envGoogleClientID :: !String
  } deriving (Eq, Show)

instance FromEnv Env where
  fromEnv _ = do
    envGoogleClientID <- env "GOOGLE_CLIENT_ID"
    pure Env {..}

-- | Application context: a combination of Env and additional values.
data Context = Context
  { contextGoogleClientID :: !String
  , contextServerPort :: !Int
  , contextClientPort :: !Int
  }

-- | Type synonym for my application monad.
type App = RIO Context

data VerifyGoogleSignInRequest = VerifyGoogleSignInRequest
  { idToken :: !Text
  } deriving (Eq, Show)

instance FromJSON VerifyGoogleSignInRequest where
  parseJSON = withObject "" $ \x -> do
    idToken <- x .: "idToken"
    pure VerifyGoogleSignInRequest{..}