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 tostopApp
, the application exits before the second call toserver
. This is catastrophic, the application does not launch.☹️ - The first call to
server
will fail if theserver
function tries to access anything insession$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!