{/* Total Tablos */}
@@ -842,7 +856,12 @@ export const TabloPage = () => {
{filterType === "all" && (
-
diff --git a/apps/main/src/providers/UserStoreProvider.tsx b/apps/main/src/providers/UserStoreProvider.tsx
index 11a0170..7a16544 100644
--- a/apps/main/src/providers/UserStoreProvider.tsx
+++ b/apps/main/src/providers/UserStoreProvider.tsx
@@ -66,6 +66,14 @@ export const useMaybeUser = () => {
return useStore(store);
};
+export const useIsReadOnlyUser = () => {
+ const store = React.useContext(UserStoreContext);
+ if (!store) {
+ throw new Error("Missing UserStoreProvider");
+ }
+ return useStore(store).is_temporary;
+};
+
// TestUserStoreProvider component
export const TestUserStoreProvider = ({
children,
diff --git a/sql/25_notes.sql b/sql/25_notes.sql
index 6e6f8d6..83547bd 100644
--- a/sql/25_notes.sql
+++ b/sql/25_notes.sql
@@ -21,11 +21,18 @@ CREATE INDEX IF NOT EXISTS idx_notes_created_at ON notes(created_at);
-- Enable Row Level Security
ALTER TABLE notes ENABLE ROW LEVEL SECURITY;
--- Policy to allow users to view their own notes
-CREATE POLICY "Users can view their own notes" ON notes
+-- Policy to allow users to view their own notes and public notes
+CREATE POLICY "Users can view their own notes and public notes" ON notes
FOR SELECT
- TO authenticated
- USING (user_id = (SELECT auth.uid()));
+ TO authenticated, anon
+ USING (
+ user_id = (SELECT auth.uid())
+ OR EXISTS (
+ SELECT 1 FROM shared_notes
+ WHERE shared_notes.note_id = notes.id
+ AND shared_notes.is_public = TRUE
+ )
+ );
-- Policy to allow users to insert their own notes
CREATE POLICY "Users can insert their own notes" ON notes
@@ -62,7 +69,7 @@ CREATE POLICY "Users can delete their own notes" ON notes
-- Add comments to document the table
COMMENT ON TABLE notes IS
- 'User notes with Row Level Security to ensure users can only access their own notes';
+ 'User notes with Row Level Security. Users can access their own notes and public notes (marked in shared_notes table)';
COMMENT ON COLUMN notes.id IS
'Primary key: random 24-character alphanumeric string';
diff --git a/sql/26_create_note_sharing_tables.sql b/sql/26_create_note_sharing_tables.sql
index c5ee154..8f5a559 100644
--- a/sql/26_create_note_sharing_tables.sql
+++ b/sql/26_create_note_sharing_tables.sql
@@ -31,7 +31,7 @@ CREATE POLICY "Users can view their own shared notes" ON shared_notes
-- Policy to allow anonymous users to view public notes
CREATE POLICY "Anyone can view public notes" ON shared_notes
FOR SELECT
- TO anon
+ TO anon, authenticated
USING (is_public = TRUE);
-- Policy to allow users to insert their own shared_notes entries