How to catch click on login dialog in shinyMobile app

I'm writing an shinyMobile app that needs to have a login interface that authenticates with Firebase, if the authentication fails then the rest of the app is not available.

I'm currently working on a way yo use f7Dialog of type `login to handle the authentication UI but I cannot seem to find a way to catch when a user presses 'ok" of the dialog to trigger an http request to authenticate with Firebase.

How do I use the click on the "ok" button to trigger the event?

Here's a reprex of what I'm doing:

  • server.R:
shinyServer(function(input, output, session) {
  
  observeEvent(input$signin_modal, {
    f7Dialog(
      id = "signin_dialog",
      title = "Iniciar sesión",
      text = "Digite su email y contraseña de Firebase ixpantia",
      type = "login",
      session = session
    )
  })
  
  observeEvent(input$login$ok, {
    print("check")
    print(input$login)
    authEmail <- input$login$user
    authPassword <- input$login$password
    print(authEmail)
    response <-
      POST(
        "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=[api_key]",
        body = list(
          email = toString(authEmail),
          password = toString(authPassword),
          returnSecureToken = TRUE
        ),
        encode = "json"
      )
    status <- http_status(response)$category
    body <- content(response, "text")
    output$status <- renderText(status)
    output$body <- renderText(body)
    print(output$status)
    if (status == 'Success' &&
        gregexpr(pattern = '"idToken"', text = body) > 0) {
      removeModal()
    } else {
      stopApp()
    }
  })
  
  # other reactive parts of the app here
})
  • ui.R:
shinyUI(f7Page(
  options = list(theme = c("md"), dark = TRUE),
  f7TabLayout(
    f7Tabs(
      animated = TRUE,
      id = "tabs",
      f7Tab(
        f7BlockTitle(title = "Inicio", size = "medium"),
        tabName = "inicio",
        icon = f7Icon("doc_person"),
        active = TRUE,
        f7Button("signin_modal", "Iniciar sesión")
      ),
      f7Tab(
        # other ui elements
        )
    )
  )
)
)
  • global.R
library(shiny)
library(shinyMobile)
library(lubridate)
library(googlesheets4)
library(purrr)
library(jsonlite)
library(lubridate)
library(glue)
library(tidyr)
library(tibble)
library(httr)

## get Firebase api from secret manager or .Renviron"
api_key <- "API_KEY"

Any help would be appreciated

Try:

observeEvent(input$signin_dialog, {}

not input$login$ok

Thanks @cezary.kuran it worked!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.