Created
January 14, 2020 12:28
-
-
Save lotz84/a191a2eb80cbd045e6545a3941bfbefe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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