firebase icon indicating copy to clipboard operation
firebase copied to clipboard

Enhancement - f$req_sign_in() which can apply to the whole app

Open pdbentley opened this issue 3 years ago • 1 comments

Hey, this package is great.

One thing I am trying to have is a seperate modal box which has to be completed before showing the rest of the app. I can see theere is this approach can be applied to indiviudual plots, e.g.

output$plot <- renderPlot({ f$req_sign_in() plot(cars) })

is it possible instead to apply this to the whole shiny app? It could be a useful reature for larger apps.

Thanks, P.

pdbentley avatar Oct 07 '21 10:10 pdbentley

I think this is already implemented. Currently you can do this by providing a modal dialog at the very beginning of your server with a combination of uiOutput(). Your code would look something like this:

library(shiny)
library(firebase)

ui <- fluidPage(
    useFirebase(),
    reqSignin(
        uiOutput("myUI")
    )
)

server <- function(input, output, session) {
    showModal(modalDialog(
        firebase::firebaseUIContainer(),
        footer = NULL
    ))
    
    f <- firebase::FirebaseUI$
        new()$ # instantiate
        set_providers( # define providers
            email = TRUE,
            google = TRUE
        )$
        launch()
    
    output$myUI <- renderUI(
        f$req_sign_in()
        # whatever
    ) 
    
    observeEvent(f$req_sign_in(), removeModal(session))
}

Another option is the code provided here which doesn't use a modal dialog.

calderonsamuel avatar Sep 09 '22 16:09 calderonsamuel

Hi,

I'm using bs4Dash and shiny modules. When I use renderUI it changes style and sidebar doesn't work.

I followed this way

ui <-  function(id) {
  fluidPage(
    home_page$ui(ns("homepage"))
  )
}
server <- function(id) {
  moduleServer(id, function(input, output, session) {
    ns <- session$ns
    showModal(modalDialog(
      title = "Sign in",
      firebase::useFirebase(firestore = TRUE),
      firebase::firebaseUIContainer(),
      footer=NULL
    ))
    f <- firebase::FirebaseUI$
      new("session")$ # instantiate
      set_providers( # define providers
        email = TRUE,
        google = TRUE
      )$
      launch() # launch

    # Add OR statement here.
    observeEvent(f$get_signed_in(),{
      removeModal()
      home_page$server("homepage")
    })

    observe({
      observeEvent(f,{
        if(!is.null(f$is_signed_in())){
          removeModal()
          home_page$server("homepage")

        }
      })
    })

  })
}

When I save my mail and pass in Chrome browser, modelDialog closing automatically but when I use Firefox after saving my mail and pass., there is only modal without firebase UI. The app link: https://bigappbeta.fly.dev/

How can I solve it?

ugurdar avatar May 28 '23 10:05 ugurdar

Apologies for the much belated response everyone, I'm terribly busy with work.

Ideally we could lock an entire app behind a login screen, I agree. As far as I know there is no real way to hijack the initial response sent by shiny.

In the meantime, the idea is mostly to use modules/functions and only call these server side if the sign in is observe.

observe(f$get_signed_in(), {
  module_something_server()
})

There's effectively no need for anything server side.

Also, I would not default to showing a login modal. Always observe on sign in and only show the modal if the user is not authenticated, otherwise just skip it. Otherwise, even if the user is signed in, the modal might flash for a second or so.

JohnCoene avatar May 30 '23 18:05 JohnCoene

Thank you!

Actually I tried to follow same approach but I guess it's about CSS issue bs4dash. I hide (shinyjs) that bs4dash module and added sys.sleep it's working at Chrome, Opera, Yandex, Edge. but still I can't seperate that module because still I can see the background black.

ui <-  function(id) {
  ns <- shiny::NS(id)
  fluidPage(
    autoWaiter(),
    useFirebase(),
    hidden(
      div(id= ns('homepage_div'),
          home_page$ui(ns("homepage"))
      )
    )
  )
}

server <- function(id) {
  moduleServer(id, function(input, output, session) {
    showModal(
      div(
         Sys.sleep(2),
          useFirebase(),
          firebase::firebaseUIContainer()
        )
      )
    )
    
    f <- firebase::FirebaseUI$
      new("session")$ # instantiate
      set_providers( # define providers
        email = TRUE,
        google = TRUE
      )$
      launch() # launch

    observeEvent(f$get_signed_in(),{
      removeModal()
      show("homepage_div")
      home_page$server("homepage")
    })
    
  })
}

In Firefox 'tracking protection' block the firebase UI. When I close and open protection I can see the firebase UI.

ugurdar avatar May 31 '23 13:05 ugurdar

Oh no, I would not be suprised Firefox and Brave block firebase.js

Just a small correction

    observeEvent(f$get_signed_in(),{
      if(isFALSE(f$get_signed_in()))
        return()
      removeModal()
      show("homepage_div")
      home_page$server("homepage")
    })

JohnCoene avatar May 31 '23 14:05 JohnCoene

Thank you for all!

ugurdar avatar May 31 '23 16:05 ugurdar