| logout {tabler} | R Documentation |
Log Out The Current Session
Description
Forces the browser to drop its session cookie and return to the login
page. For use inside a tabler_app server function
(e.g. in an observe_event() on a "Log out" button) when
check_credentials was supplied to tabler_app.
Usage
logout(session = get_default_reactive_domain())
Arguments
session |
The session object passed by tabler_app
to the server function. Defaults to get_default_reactive_domain().
|
Details
Why this can't be done by just hiding a DOM element
Unlike show_progress/hide_progress, which only
toggle a cosmetic overlay, a login gate has to withhold the actual page
content from the browser until the server has verified the visitor -
anything already sent to the browser (HTML, JS, JSON) can always be
revealed again with the browser's DevTools, no matter how it is hidden
client-side. tabler_app therefore checks a signed session
cookie before it ever renders the page, serves cached outputs, or
accepts a WebSocket connection: an unauthenticated request gets nothing
but the login form, both for the initial page load and for the
WebSocket handshake that carries reactive output.
logout() sends a small message over the WebSocket telling the
browser-side JS (tabler-login.js) to navigate to /logout,
which is a real server-side endpoint that clears the session cookie and
redirects back to /login. This is the same show/hide message
mechanism as show_progress, but logout can only actually
take effect through the server, not through anything client-side.
Value
Invisibly, NULL.
See Also
tabler_app
Examples
if (interactive()) {
ui <- page(
title = "Login Example",
body = body(action_button("logout_btn", "Log out"))
)
server <- function(input, output, session) {
observe_event(input$logout_btn, {
logout(session)
})
}
tabler_app(
ui, server,
check_credentials = function(username, password) {
username == "admin" && password == "hunter2"
}
)
}