Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirebaseUI$new(persistence = "local") login atuomatically hide `firebaseUIContainer( #82

Closed
HugoGit39 opened this issue Apr 25, 2024 · 2 comments

Comments

@HugoGit39
Copy link

Hi!

This is not an issue, perhaps a feature, but I wonder the following:

If I set persistence = "local" login is automatically which is super!

However when the app is opened, every time the login container firebaseUIContainer() is shown briefly where the login is continued. Is there a way to hide the container when someone already is logged in? I

f = FirebaseUI$new(persistence = "local")$
      set_providers(
        email = T
      )$
      set_tos_url(tos_url)$
      set_privacy_policy_url(privacy_url)$
      launch()
@JohnCoene
Copy link
Owner

It's a great solution but it works.

library(shiny)
library(firebase)

ui <- fluidPage(
  useFirebase(),
  tags$head(
    tags$script(
      # ui must be present at launch so we leave it there but hide it
      HTML(
        "Shiny.addCustomMessageHandler('show-login', (msg) => {
          $('#ui-wrapper').show();
        })"
      )
    )
  ),
  div(
    id = "ui-wrapper",
    style = "display: none;",
    firebaseUIContainer()
  ),
  reqSignin(actionButton("signout", "Sign out")),
  uiOutput("msg"),
  plotOutput("plot")
)

server <- function(input, output, session){
  f <- FirebaseUI$
    new("local")$
    set_providers(
      email = TRUE,
      yahoo = TRUE,
      google = TRUE,
      github = TRUE,
      twitter = TRUE,
      facebook = TRUE,
      microsoft = TRUE
    )$
    launch()

  output$plot <- renderPlot({
    f$req_sign_in() # require sign in
    plot(cars)
  })

  # Sign in runs twice hence this check
  ran <- 0L
  observe({
    user <- f$get_signed_in() # get logged in user info

    ran <<- ran + 1L

    if(ran < 2L)
      return()

    if(is.null(user))
      session$sendCustomMessage("show-login", list())
  })

  output$msg <- renderUI({
    f$req_sign_in() # require sign in

    user <- f$get_signed_in() # get logged in user info
    print(user)

    h4("Welcome,", user$response$displayName)
  })

  observeEvent(input$signout, {
    f$sign_out()
  })

}

shinyApp(ui, server)

@HugoGit39
Copy link
Author

SUPER! Works! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants