Skip to content

Commit 630073b

Browse files
committed
Improve authentication example
On the main page, display 'logout' only if the user is logged in. Display 'login' and 'signup' only if they are not. See #55
1 parent 6a42e05 commit 630073b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

examples/user-authentication/index.sql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
WITH logged_in AS (
2+
SELECT COALESCE(sqlpage.cookie('session'), '') <> '' AS logged_in
3+
)
14
SELECT 'shell' AS component,
25
'User Management App' AS title,
36
'user' AS icon,
47
'/' AS link,
5-
'signin' AS menu_item,
6-
'signup' AS menu_item;
8+
json_agg(menu_items.link) AS menu_item
9+
FROM (
10+
SELECT 'signin' AS link FROM logged_in WHERE NOT logged_in
11+
UNION ALL
12+
SELECT 'signup' FROM logged_in WHERE NOT logged_in
13+
UNION ALL
14+
SELECT 'logout' FROM logged_in WHERE logged_in
15+
) AS menu_items;
716

817
SELECT 'hero' AS component,
918
'SQLPage Authentication Demo' AS title,

0 commit comments

Comments
 (0)