-
Notifications
You must be signed in to change notification settings - Fork 0
P2 client cutover #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d4c706a
docs(spec): P2 client cutover onto the pages graph design
coderhd 23bde35
docs(plan): P2 client cutover implementation plan
coderhd 4f97be3
feat(db): page-only authority, page invitations, pages-aware version …
coderhd 9bc1c4e
fix(db): harden page invitation RLS against role and page pivoting
coderhd fcc7d1f
fix(db): qualify outer column refs in page member self-insert policy
coderhd 8c845ac
fix(auth): page-only authority in verifyUserRole, public pages grant …
coderhd 0f2fee3
test(auth): harden document_members-ignored regression guard with leg…
coderhd 95f2124
feat(graph): page member/invite service layer and workspace bootstrap
coderhd 07c52e8
feat(dashboard): cut over to pages and page members
coderhd ae8cac4
feat(editor): page route with /doc redirect and pages-based workspace
coderhd a5e6ca5
feat(share): page member management in share modal
coderhd e7cb4a0
feat(invites): page invitations across notifications, banner and invi…
coderhd 234296f
feat(settings): collaborators tab backed by pages and page members
coderhd 0f007c5
fix(settings): guard owner from role select, pages copy
coderhd b37cd62
feat(versions): pages-aware checkpoints and API route
coderhd 521ab8a
fix(db): slot-based select_pages so INSERT ... RETURNING works for pa…
coderhd 8856c61
fix(review): page-only versions, invitation immutability, version aut…
coderhd 33c7c7f
fix(db): exactly-one version owner constraint; invitation immutabilit…
coderhd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,100 +1,10 @@ | ||
| 'use client' | ||
| import { redirect } from 'next/navigation' | ||
|
|
||
| import { use, useState, useEffect } from 'react' | ||
| import { useRouter } from 'next/navigation' | ||
| import { supabase } from '@/lib/supabase' | ||
| import { fetchDocumentDetails } from '@/services/db' | ||
| import GlobalLoader from '@/components/global-loader' | ||
| import EditorWorkspace from '@/components/editor-workspace' | ||
| import { toast } from 'sonner' | ||
|
|
||
| export default function DocumentPage({ | ||
| export default async function DocumentPage({ | ||
| params: paramsPromise, | ||
| }: { | ||
| params: Promise<{ id: string }> | ||
| }) { | ||
| const params = use(paramsPromise) | ||
| const router = useRouter() | ||
| const [user, setUser] = useState<any | null>(null) | ||
| const [token, setToken] = useState<string | null>(null) | ||
| const [documentTitle, setDocumentTitle] = useState<string | null>(null) | ||
| const [loading, setLoading] = useState(true) | ||
|
|
||
| useEffect(() => { | ||
| const loadDocumentAndSession = async () => { | ||
| try { | ||
| // 1. Get current session and token | ||
| const { data: { session } } = await supabase.auth.getSession() | ||
| const { error: userError } = await supabase.auth.getUser() | ||
|
|
||
| // If there is an auth error that is NOT just a missing session, it means the token expired or is invalid | ||
| if (userError && userError.name !== 'AuthSessionMissingError') { | ||
| console.error('Session error (token expired):', userError) | ||
| toast.error('Session expired. Please log in again.') | ||
| router.push('/login') | ||
| return | ||
| } | ||
|
|
||
| if (session) { | ||
| setUser(session.user) | ||
| setToken(session.access_token) | ||
| } else { | ||
| // Check if document is public | ||
| try { | ||
| const doc = await fetchDocumentDetails(params.id) | ||
| if (doc && doc.is_public) { | ||
| // Mock anonymous user | ||
| const randomId = Math.random().toString(36).substring(7) | ||
| setUser({ | ||
| id: `anon-${randomId}`, | ||
| email: 'anonymous@public', | ||
| full_name: 'Anonymous Viewer' | ||
| }) | ||
| setToken('anonymous') | ||
| } else { | ||
| router.push('/login') | ||
| return | ||
| } | ||
| } catch { | ||
| router.push('/login') | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // 2. Fetch document details using wrapper service | ||
| const doc = await fetchDocumentDetails(params.id) | ||
| setDocumentTitle(doc.title) | ||
| } catch (err: unknown) { | ||
|
|
||
| console.error('Error loading document page:', err) | ||
| toast.error('Document not found or access denied') | ||
| router.push('/') | ||
| } finally { | ||
| setLoading(false) | ||
| } | ||
| } | ||
|
|
||
| loadDocumentAndSession() | ||
| }, [params.id, router]) | ||
|
|
||
| if (loading) { | ||
| return <GlobalLoader text="Loading document..." /> | ||
| } | ||
|
|
||
| if (!user || !token || !documentTitle) { | ||
| return null | ||
| } | ||
|
|
||
| return ( | ||
| <EditorWorkspace | ||
| documentId={params.id} | ||
| initialTitle={documentTitle} | ||
| token={token} | ||
| currentUser={{ | ||
| id: user.id, | ||
| email: user.email, | ||
| full_name: user.user_metadata?.full_name || user.full_name | ||
| }} | ||
| /> | ||
| ) | ||
| const params = await paramsPromise | ||
| redirect(`/page/${params.id}`) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| 'use client' | ||
|
|
||
| import { use, useState, useEffect } from 'react' | ||
| import { useRouter } from 'next/navigation' | ||
| import { supabase } from '@/lib/supabase' | ||
| import { fetchPageDetails } from '@/services/graph' | ||
| import GlobalLoader from '@/components/global-loader' | ||
| import EditorWorkspace from '@/components/editor-workspace' | ||
| import { toast } from 'sonner' | ||
|
|
||
| export default function PageRoute({ | ||
| params: paramsPromise, | ||
| }: { | ||
| params: Promise<{ id: string }> | ||
| }) { | ||
| const params = use(paramsPromise) | ||
| const router = useRouter() | ||
| const [user, setUser] = useState<any | null>(null) | ||
| const [token, setToken] = useState<string | null>(null) | ||
| const [pageTitle, setPageTitle] = useState<string | null>(null) | ||
| const [loading, setLoading] = useState(true) | ||
|
|
||
| useEffect(() => { | ||
| const loadPageAndSession = async () => { | ||
| try { | ||
| // 1. Get current session and token | ||
| const { data: { session } } = await supabase.auth.getSession() | ||
| const { error: userError } = await supabase.auth.getUser() | ||
|
|
||
| // If there is an auth error that is NOT just a missing session, it means the token expired or is invalid | ||
| if (userError && userError.name !== 'AuthSessionMissingError') { | ||
| console.error('Session error (token expired):', userError) | ||
| toast.error('Session expired. Please log in again.') | ||
| router.push('/login') | ||
| return | ||
| } | ||
|
|
||
| if (session) { | ||
| setUser(session.user) | ||
| setToken(session.access_token) | ||
| } else { | ||
| // Check if page is public | ||
| try { | ||
| const page = await fetchPageDetails(params.id) | ||
| if (page && page.is_public) { | ||
| // Mock anonymous user | ||
| const randomId = Math.random().toString(36).substring(7) | ||
| setUser({ | ||
| id: `anon-${randomId}`, | ||
| email: 'anonymous@public', | ||
| full_name: 'Anonymous Viewer' | ||
| }) | ||
| setToken('anonymous') | ||
| } else { | ||
| router.push('/login') | ||
| return | ||
| } | ||
| } catch { | ||
| router.push('/login') | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // 2. Fetch page details | ||
| const page = await fetchPageDetails(params.id) | ||
| setPageTitle(page.title) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } catch (err: unknown) { | ||
| console.error('Error loading page:', err) | ||
| toast.error('Page not found or access denied') | ||
| router.push('/') | ||
| } finally { | ||
| setLoading(false) | ||
| } | ||
| } | ||
|
|
||
| loadPageAndSession() | ||
| }, [params.id, router]) | ||
|
|
||
| if (loading) { | ||
| return <GlobalLoader text="Loading page..." /> | ||
| } | ||
|
|
||
| if (!user || !token || !pageTitle) { | ||
| return null | ||
| } | ||
|
|
||
| return ( | ||
| <EditorWorkspace | ||
| pageId={params.id} | ||
| initialTitle={pageTitle} | ||
| token={token} | ||
| currentUser={{ | ||
| id: user.id, | ||
| email: user.email, | ||
| full_name: user.user_metadata?.full_name || user.full_name | ||
| }} | ||
| /> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: coderhd/lekhan
Length of output: 26139
🏁 Script executed:
Repository: coderhd/lekhan
Length of output: 36122
🏁 Script executed:
Repository: coderhd/lekhan
Length of output: 50372
🏁 Script executed:
Repository: coderhd/lekhan
Length of output: 19605
Reject non-pending invitations and make acceptance atomic.
The route renders Accept Invitation for declined invitations.
acceptPageInvitationdoes not enforce the current status before its separate membership insert and status update. Use a database transaction or RPC that checksstatus = 'pending'and the authenticated invitee before both writes. Apply the same transition and immutable-field restrictions in RLS.🤖 Prompt for AI Agents