Skip to content

Instantly share code, notes, and snippets.

@lotz84
Created January 14, 2020 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotz84/a191a2eb80cbd045e6545a3941bfbefe to your computer and use it in GitHub Desktop.
Save lotz84/a191a2eb80cbd045e6545a3941bfbefe to your computer and use it in GitHub Desktop.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Firebase.Auth where
import Data.Text.Lazy (Text)
import Data.Extensible
import Servant.API
import Servant.Client
type family Req a
type family Res a
-- | https://firebase.google.com/docs/reference/rest/auth#section-create-email-password
data SignUp
type instance Req SignUp = Record
'[ "email" >: Text
, "password" >: Text
, "returnSecureToken" >: Bool
]
type instance Res SignUp = Record '["idToken" >: Text, "email" >: Text, "refreshToken" >: Text, "expiresIn" >: Text, "localId" >: Text]
-- | https://firebase.google.com/docs/reference/rest/auth#section-sign-in-email-password
data SignInWithPassword
type instance Req SignInWithPassword = Record '["email" >: Text, "password" >: Text, "returnSecureToken" >: Bool]
type instance Res SignInWithPassword = Record '["idToken" >: Text, "email" >: Text, "refreshToken" >: Text, "expiresIn" >: Text, "localId" >: Text, "registered" >: Bool]
type IdentitytoolkitAPI = "v1" :> "accounts:signUp" :> QueryParam "key" Text :> ReqBody '[JSON] (Req SignUp) :> Post '[JSON] (Res SignUp)
:<|> "v1" :> "accounts:signInWithPassword" :> QueryParam "key" Text :> ReqBody '[JSON] (Req SignInWithPassword) :> Post '[JSON] (Res SignInWithPassword)
postSignUp :: Maybe Text -> Req SignUp -> ClientM (Res SignUp)
postSignInWithPassword :: Maybe Text -> Req SignInWithPassword -> ClientM (Res SignInWithPassword)
postSignUp :<|> postSignInWithPassword = client (Proxy @IdentitytoolkitAPI)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment