CREATE FUNCTION _api.get_user_id()
RETURNS INTEGER
LANGUAGE plpgsql VOLATILE
AS $BODY$
DECLARE
	_user_id INTEGER;
BEGIN
	_user_id = CURRENT_SETTING(
		'request.jwt.claims',
		TRUE
	)::JSON->>'user_id';

	UPDATE xssbook.user
	SET seen = clock_timestamp()
	WHERE id = _user_id;

	RETURN _user_id;
END
$BODY$;

GRANT UPDATE ON TABLE xssbook.user
	TO rest_anon, rest_user;
