This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
server.R
81 lines (59 loc) · 1.96 KB
/
server.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function(input, output, session) {
##### Switch Views ------------------
# if user click link to register, go to register view
observeEvent(input$go_to_register, {
shinyjs::show("register_panel", anim = TRUE, animType = "fade")
shinyjs::hide("sign_in_panel")
}, ignoreInit = TRUE)
observeEvent(input$go_to_sign_in, {
shinyjs::hide("register_panel")
shinyjs::show("sign_in_panel", anim = TRUE, animType = "fade")
}, ignoreInit = TRUE)
# switch between auth sign in/registration and app for signed in user
observeEvent(session$userData$current_user(), {
current_user <- session$userData$current_user()
if (is.null(current_user)) {
shinyjs::show("sign_in_panel")
shinyjs::hide("main")
shinyjs::hide("verify_email_view")
} else {
shinyjs::hide("sign_in_panel")
shinyjs::hide("register_panel")
if (current_user$emailVerified == TRUE) {
shinyjs::show("main")
} else {
shinyjs::show("verify_email_view")
}
}
}, ignoreNULL = FALSE)
# Signed in user --------------------
# the `session$userData$current_user()` reactiveVal will hold information about the user
# that has signed in through Firebase. A value of NULL will be used if the user is not
# signed in
session$userData$current_user <- reactiveVal(NULL)
# input$sof_auth_user comes from front end js in "www/sof-auth.js"
observeEvent(input$sof_auth_user, {
# set the signed in user
session$userData$current_user(input$sof_auth_user)
}, ignoreNULL = FALSE)
##### App for signed in user
signed_in_user_df <- reactive({
req(session$userData$current_user())
out <- session$userData$current_user()
out <- unlist(out)
data.frame(
name = names(out),
value = unname(out)
)
})
output$user_out <- DT::renderDT({
datatable(
signed_in_user_df(),
rownames = FALSE,
options = list(
dom = "tp",
scrollX = TRUE
)
)
})
}