--------------------------------------------------------------------------------
-- Passwordless    

-- | Authentification via email
--    
passwordlessEmail :: T.Text -> EmailType -> Config -> ExceptT T.Text IO RespEmail
passwordlessEmail email' type' Config{..} = do
  resp <- liftIO $ post (T.unpack $ basePath <> "/passwordless/start") requestParams
  case AE.eitherDecode (resp ^. responseBody ) of
    (Left err)  -> throwError $ T.pack $ show err
    (Right tok) -> return tok
  where 
    requestParams =
      [ "client_id"  :=  clientId  
      , "connection" :=  ("email" :: T.Text)
      , "email"      :=  email' 
      , "send"       :=  sendType  -- "link" or "code"
      , "authParams" :=  (""::T.Text)   
      ]
    sendType = T.pack $ map toLower $ show type'

-- | Authentification via sms
--      
passwordlessEmail :: T.Text -> EmailType -> Config -> ExceptT T.Text IO RespEmail
passwordlessEmail email' type' Config{..} = do
  resp <- liftIO $ post (T.unpack $ basePath <> "/passwordless/start") requestParams
  case AE.eitherDecode (resp ^. responseBody ) of
    (Left err)  -> throwError $ T.pack $ show err
    (Right tok) -> return tok
  where 
    requestParams =
      [ "client_id"  :=  clientId  
      , "connection" :=  ("email" :: T.Text)
      , "email"      :=  email' 
      , "send"       :=  sendType  -- "link" or "code"
      , "authParams" :=  (""::T.Text)   
      ]
    sendType = T.pack $ map toLower $ show type'

-- | Authentification via sms
--      
passwordlessEmail email' type' Config{..} = do
  resp <- liftIO $ post (T.unpack $ basePath <> "/passwordless/start") requestParams
  case AE.eitherDecode (resp ^. responseBody ) of
    (Left err)  -> throwError $ T.pack $ show err
    (Right tok) -> return tok
  where 
    requestParams =
      [ "client_id"  :=  clientId  
      , "connection" :=  ("email" :: T.Text)
      , "email"      :=  email' 
      , "send"       :=  sendType  -- "link" or "code"
      , "authParams" :=  (""::T.Text)   
      ]
    sendType = T.pack $ map toLower $ show type'

-- | Authentification via sms
--      