Skip to content

Shiny server function is called twice when browser is Firefox #77

Open
@AB-Kent

Description

I'm using Auth0 from a Shiny app. When the app runs in Chrome, the server function is called once, after the user logs in, with session$userData populated with the auth0_credentials and auth0_info. This is good 😺

When the app runs in Firefox, the server function is called twice - once immediately, with no session$userData, and again after the user logs in, with session$userData populated. If a session$onSessionEnded callback has been registered, it is called after the first call to server.

This is bad for a couple of reasons:

  • If session$onSessionEnded is used conventionally to register a call to stopApp, the application exits before the second call to server. This is catastrophic, the application does not launch. ☹️
  • The first call to server will fail if the server function tries to access anything in session$userData. This is merely annoying since the function is called again.

Here is a minimal reprex (you must supply your own _auth0.yml and .Renviron files):

library(shiny)
library(purrr) # for `pluck`

ui <- fluidPage(
    titlePanel("Firefox test"),

    sidebarLayout(
        sidebarPanel(
            auth0::logoutButton()
        )
    )
)

server <- function(input, output, session) {

    cat('Entered `server` function\n')
    
    # Safe navigation to user name
    cat('User name is', 
        purrr::pluck(session, 'userData', 'auth0_info', 'name'), '\n')
    
    session$onSessionEnded(function() {
        cat('Session ended\n')
    })
}

options(shiny.port = 4200)
auth0::shinyAppAuth0(ui, server)

When I run this on Chrome, the output is

Entered `server` function
User name is kent johnson 

with no output appearing until after I log in.

When I run on Firefox, the output is

Entered `server` function
User name is 
Session ended
Entered `server` function
User name is kent johnson 

where the first three lines are output before I complete the login sequence.

What is causing the double call to server and how can I prevent it?

Thanks!

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions