From 944b6b0526032ad8c1b4a2612d6723bec75e0e4c Mon Sep 17 00:00:00 2001
From: Freya Murphy <freya@freyacat.org>
Date: Fri, 29 Mar 2024 22:29:56 -0400
Subject: start database (user and post), and initial barebones home page

---
 db/rest/util/_api_get_user_id.sql | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 db/rest/util/_api_get_user_id.sql

(limited to 'db/rest/util/_api_get_user_id.sql')

diff --git a/db/rest/util/_api_get_user_id.sql b/db/rest/util/_api_get_user_id.sql
new file mode 100644
index 0000000..23eb160
--- /dev/null
+++ b/db/rest/util/_api_get_user_id.sql
@@ -0,0 +1,11 @@
+CREATE FUNCTION _api.get_user_id()
+RETURNS INTEGER
+LANGUAGE plpgsql VOLATILE
+AS $BODY$
+BEGIN
+	RETURN CURRENT_SETTING(
+		'request.jwt.claims',
+		TRUE
+	)::JSON->>'user_id';
+END
+$BODY$;
-- 
cgit v1.2.3-freya

