Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/db/migration_add_is_approved.sql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS is_approved BOOLEAN NOT NULL DEFAULT false;
11 changes: 6 additions & 5 deletions backend/db/supabase_schema.sql
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,11 +10,12 @@ CREATE TABLE IF NOT EXISTS users (
email TEXT,
streak_count INTEGER DEFAULT 0,
last_active_date TEXT,
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google'
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google',
is_approved BOOLEAN NOT NULL DEFAULT false
);

CREATE INDEX IF NOT EXISTS idx_users_google_id ON users(google_id);
Expand Down
20 changes: 18 additions & 2 deletions backend/routes/auth.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,6 +68,15 @@ def _generate_pkce_pair():
return code_verifier, code_challenge


@router.get("/me")
def get_me(user_id: str = Query(...)):
"""Return approval status for a given user_id (used by Next.js session API route)."""
user = table("users").select("id,is_approved", filters={"id": f"eq.{user_id}"})
if not user:
raise HTTPException(status_code=404, detail="User not found")
return {"user_id": user_id, "is_approved": bool(user[0]["is_approved"])}


@router.get("/google")
def google_login():
"""Redirect to Google consent screen with identity + calendar scopes."""
Expand DownExpand Up@@ -117,19 +126,21 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
)

# Determine user_id: check if this Google ID already exists
existing = table("users").select("id", filters={"google_id": f"eq.{google_id}"})
existing = table("users").select("id,is_approved", filters={"google_id": f"eq.{google_id}"})
if existing:
user_id = existing[0]["id"]
is_approved = existing[0]["is_approved"]
# Update name/avatar in case they changed
table("users").update(
{"name": name, "avatar_url": avatar_url, "email": email},
filters={"id": f"eq.{user_id}"},
)
else:
# Check if a user with this email exists (migration from old system)
email_match = table("users").select("id", filters={"email": f"eq.{email}"})
email_match = table("users").select("id,is_approved", filters={"email": f"eq.{email}"})
if email_match:
user_id = email_match[0]["id"]
is_approved = email_match[0]["is_approved"]
table("users").update(
{
"google_id": google_id,
Expand All@@ -142,6 +153,7 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
else:
# Create new user
user_id = f"user_{google_id}"
is_approved = False
table("users").insert({
"id": user_id,
"name": name,
Expand All@@ -162,10 +174,14 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
on_conflict="user_id",
)

if not is_approved:
return RedirectResponse(f"{FRONTEND_URL}/pending")

# Redirect to frontend with user info
params = urlencode({
"user_id": user_id,
"name": name,
"avatar": avatar_url,
"is_approved": "true",
})
return RedirectResponse(f"{FRONTEND_URL}/signin/callback?{params}")
55 changes: 55 additions & 0 deletions frontend/src/app/api/auth/session/route.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
import { NextRequest, NextResponse } from 'next/server';
import { signSession, SESSION_MAX_AGE } from '@/lib/sessionToken';

const API_URL = process.env.NEXT_PUBLIC_API_URL;

export async function POST(request: NextRequest) {
if (!API_URL) {
return NextResponse.json({ error: 'NEXT_PUBLIC_API_URL not configured' }, { status: 500 });
}

const { userId } = await request.json();
if (!userId || typeof userId !== 'string') {
return NextResponse.json({ error: 'Missing userId' }, { status: 400 });
}

// Verify with the backend that the user exists and is approved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove the obvious inline comment to match repo style.

Line 12 explains directly-following code and is not non-obvious logic.

As per coding guidelines, "No docstrings or comments unless the logic is non-obvious".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@frontend/src/app/api/auth/session/route.ts` at line 12, Remove the inline
comment "// Verify with the backend that the user exists and is approved." from
the session route handler code (the comment directly above the backend
user/approval verification block) so the file no longer contains
obvious-following-code comments; leave the surrounding verification logic (the
handler/function that performs the backend user existence/approval check)
unchanged.

let approved = false;
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 3000);
let res: Response;
try {
res = await fetch(`${API_URL}/auth/me?user_id=${encodeURIComponent(userId)}`, { signal: controller.signal });
} finally {
clearTimeout(timeout);
}
if (!res.ok) {
return NextResponse.json({ error: 'User not found' }, { status: 401 });
}
const data = await res.json();
approved = data.is_approved === true;
} catch {
return NextResponse.json({ error: 'Backend unreachable' }, { status: 502 });
}

if (!approved) {
return NextResponse.json({ error: 'Not approved' }, { status: 403 });
}

const token = await signSession(userId);
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', token, {
httpOnly: true,
sameSite: 'lax',
path: '/',
maxAge: SESSION_MAX_AGE,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return response;
}

export async function DELETE() {
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', '', { httpOnly: true, maxAge: 0, path: '/' });
return response;
}
78 changes: 78 additions & 0 deletions frontend/src/app/pending/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
'use client';

import { useRouter } from 'next/navigation';
import Image from 'next/image';
import { useUser } from '@/context/UserContext';

export default function PendingPage() {
const router = useRouter();
const { signOut } = useUser();

async function handleSignOut() {
await signOut();
router.replace('/signin');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
color: 'var(--brand-text1, #e6edf3)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>
<h1 style={{
fontSize: '28px',
fontWeight: 600,
marginBottom: '12px',
textAlign: 'center',
letterSpacing: '-0.02em',
}}>
You&apos;re on the waitlist
</h1>
<p style={{
fontSize: '15px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
maxWidth: '340px',
lineHeight: 1.6,
marginBottom: '40px',
}}>
We&apos;ll reach out when your access is approved.
</p>
<button
onClick={handleSignOut}
style={{
background: 'transparent',
border: '1px solid rgba(255,255,255,0.15)',
color: 'var(--brand-text2, #8b949e)',
padding: '10px 24px',
borderRadius: '8px',
fontSize: '14px',
cursor: 'pointer',
transition: 'border-color 0.2s, color 0.2s',
}}
onMouseEnter={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.35)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text1, #e6edf3)';
}}
onMouseLeave={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.15)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text2, #8b949e)';
}}
>
Sign out
</button>
</div>
);
}
24 changes: 21 additions & 3 deletions frontend/src/app/signin/callback/page.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,18 +7,36 @@ import { useUser } from '@/context/UserContext';
function CallbackInner() {
const searchParams = useSearchParams();
const router = useRouter();
const { setActiveUser } = useUser();
const { setActiveUser, confirmApproved } = useUser();

useEffect(() => {
const userId = searchParams.get('user_id');
const name = searchParams.get('name');
const avatar = searchParams.get('avatar');
const isApproved = searchParams.get('is_approved') === 'true';
const error = searchParams.get('error');

if (error === 'not_approved' || !isApproved) {
router.replace('/pending');
return;
}

if (userId && name) {
setActiveUser(userId, name, avatar || '');
router.replace('/');
fetch('/api/auth/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId }),
}).then(res => {
if (res.ok) {
confirmApproved();
router.replace('/dashboard');
} else {
router.replace('/signin');
}
});
} else {
router.replace('/');
router.replace('/signin');
}
}, []); // eslint-disable-line react-hooks/exhaustive-deps

Expand Down
114 changes: 114 additions & 0 deletions frontend/src/app/signin/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
'use client';

import { Suspense } from 'react';
import { useSearchParams } from 'next/navigation';
import Image from 'next/image';

const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:5000';

function SignInInner() {
const searchParams = useSearchParams();
const error = searchParams.get('error');

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>

{error === 'not_approved' && (
<div style={{
marginBottom: '24px',
padding: '12px 20px',
borderRadius: '8px',
background: 'rgba(234, 179, 8, 0.12)',
border: '1px solid rgba(234, 179, 8, 0.3)',
color: '#ca8a04',
fontSize: '14px',
textAlign: 'center',
maxWidth: '360px',
}}>
Your account is pending approval.
</div>
)}

<div style={{
background: 'var(--bg-panel, #161b22)',
border: '1px solid rgba(255,255,255,0.08)',
borderRadius: '16px',
padding: '40px',
width: '100%',
maxWidth: '380px',
}}>
<h2 style={{
fontSize: '22px',
fontWeight: 600,
color: 'var(--brand-text1, #e6edf3)',
textAlign: 'center',
marginBottom: '8px',
letterSpacing: '-0.02em',
}}>
Welcome back
</h2>
<p style={{
fontSize: '14px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
marginBottom: '28px',
}}>
Sign in to continue
</p>

<button
onClick={() => { window.location.href = `${API_URL}/api/auth/google`; }}
style={{
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '12px',
padding: '12px 20px',
background: '#ffffff',
border: '1px solid #d1d5db',
borderRadius: '10px',
fontSize: '14px',
fontWeight: 500,
color: '#111827',
cursor: 'pointer',
transition: 'box-shadow 0.2s',
}}
onMouseEnter={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = '0 2px 8px rgba(0,0,0,0.12)'; }}
onMouseLeave={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = 'none'; }}
>
<svg width="18" height="18" viewBox="0 0 24 24">
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4" />
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853" />
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05" />
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335" />
</svg>
Continue with Google
</button>
</div>
</div>
);
}

export default function SignInPage() {
return (
<Suspense fallback={<div style={{ minHeight: '100vh', background: '#0d1117' }} />}>
<SignInInner />
</Suspense>
);
}
4 changes: 2 additions & 2 deletions frontend/src/components/Navbar.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,10 +89,10 @@ export default function Navbar() {
}
};

const handleSignOut = () => {
const handleSignOut = async () => {
setMenuOpen(false);
setMobileNavOpen(false);
signOut();
await signOut();
router.push('/');
};

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/db/migration_add_is_approved.sql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS is_approved BOOLEAN NOT NULL DEFAULT false;
11 changes: 6 additions & 5 deletions backend/db/supabase_schema.sql
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,11 +10,12 @@ CREATE TABLE IF NOT EXISTS users (
email TEXT,
streak_count INTEGER DEFAULT 0,
last_active_date TEXT,
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google'
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google',
is_approved BOOLEAN NOT NULL DEFAULT false
);

CREATE INDEX IF NOT EXISTS idx_users_google_id ON users(google_id);
Expand Down
20 changes: 18 additions & 2 deletions backend/routes/auth.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,6 +68,15 @@ def _generate_pkce_pair():
return code_verifier, code_challenge


@router.get("/me")
def get_me(user_id: str = Query(...)):
"""Return approval status for a given user_id (used by Next.js session API route)."""
user = table("users").select("id,is_approved", filters={"id": f"eq.{user_id}"})
if not user:
raise HTTPException(status_code=404, detail="User not found")
return {"user_id": user_id, "is_approved": bool(user[0]["is_approved"])}


@router.get("/google")
def google_login():
"""Redirect to Google consent screen with identity + calendar scopes."""
Expand DownExpand Up@@ -117,19 +126,21 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
)

# Determine user_id: check if this Google ID already exists
existing = table("users").select("id", filters={"google_id": f"eq.{google_id}"})
existing = table("users").select("id,is_approved", filters={"google_id": f"eq.{google_id}"})
if existing:
user_id = existing[0]["id"]
is_approved = existing[0]["is_approved"]
# Update name/avatar in case they changed
table("users").update(
{"name": name, "avatar_url": avatar_url, "email": email},
filters={"id": f"eq.{user_id}"},
)
else:
# Check if a user with this email exists (migration from old system)
email_match = table("users").select("id", filters={"email": f"eq.{email}"})
email_match = table("users").select("id,is_approved", filters={"email": f"eq.{email}"})
if email_match:
user_id = email_match[0]["id"]
is_approved = email_match[0]["is_approved"]
table("users").update(
{
"google_id": google_id,
Expand All@@ -142,6 +153,7 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
else:
# Create new user
user_id = f"user_{google_id}"
is_approved = False
table("users").insert({
"id": user_id,
"name": name,
Expand All@@ -162,10 +174,14 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
on_conflict="user_id",
)

if not is_approved:
return RedirectResponse(f"{FRONTEND_URL}/pending")

# Redirect to frontend with user info
params = urlencode({
"user_id": user_id,
"name": name,
"avatar": avatar_url,
"is_approved": "true",
})
return RedirectResponse(f"{FRONTEND_URL}/signin/callback?{params}")
55 changes: 55 additions & 0 deletions frontend/src/app/api/auth/session/route.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
import { NextRequest, NextResponse } from 'next/server';
import { signSession, SESSION_MAX_AGE } from '@/lib/sessionToken';

const API_URL = process.env.NEXT_PUBLIC_API_URL;

export async function POST(request: NextRequest) {
if (!API_URL) {
return NextResponse.json({ error: 'NEXT_PUBLIC_API_URL not configured' }, { status: 500 });
}

const { userId } = await request.json();
if (!userId || typeof userId !== 'string') {
return NextResponse.json({ error: 'Missing userId' }, { status: 400 });
}

// Verify with the backend that the user exists and is approved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove the obvious inline comment to match repo style.

Line 12 explains directly-following code and is not non-obvious logic.

As per coding guidelines, "No docstrings or comments unless the logic is non-obvious".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@frontend/src/app/api/auth/session/route.ts` at line 12, Remove the inline
comment "// Verify with the backend that the user exists and is approved." from
the session route handler code (the comment directly above the backend
user/approval verification block) so the file no longer contains
obvious-following-code comments; leave the surrounding verification logic (the
handler/function that performs the backend user existence/approval check)
unchanged.

let approved = false;
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 3000);
let res: Response;
try {
res = await fetch(`${API_URL}/auth/me?user_id=${encodeURIComponent(userId)}`, { signal: controller.signal });
} finally {
clearTimeout(timeout);
}
if (!res.ok) {
return NextResponse.json({ error: 'User not found' }, { status: 401 });
}
const data = await res.json();
approved = data.is_approved === true;
} catch {
return NextResponse.json({ error: 'Backend unreachable' }, { status: 502 });
}

if (!approved) {
return NextResponse.json({ error: 'Not approved' }, { status: 403 });
}

const token = await signSession(userId);
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', token, {
httpOnly: true,
sameSite: 'lax',
path: '/',
maxAge: SESSION_MAX_AGE,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return response;
}

export async function DELETE() {
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', '', { httpOnly: true, maxAge: 0, path: '/' });
return response;
}
78 changes: 78 additions & 0 deletions frontend/src/app/pending/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
'use client';

import { useRouter } from 'next/navigation';
import Image from 'next/image';
import { useUser } from '@/context/UserContext';

export default function PendingPage() {
const router = useRouter();
const { signOut } = useUser();

async function handleSignOut() {
await signOut();
router.replace('/signin');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
color: 'var(--brand-text1, #e6edf3)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>
<h1 style={{
fontSize: '28px',
fontWeight: 600,
marginBottom: '12px',
textAlign: 'center',
letterSpacing: '-0.02em',
}}>
You&apos;re on the waitlist
</h1>
<p style={{
fontSize: '15px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
maxWidth: '340px',
lineHeight: 1.6,
marginBottom: '40px',
}}>
We&apos;ll reach out when your access is approved.
</p>
<button
onClick={handleSignOut}
style={{
background: 'transparent',
border: '1px solid rgba(255,255,255,0.15)',
color: 'var(--brand-text2, #8b949e)',
padding: '10px 24px',
borderRadius: '8px',
fontSize: '14px',
cursor: 'pointer',
transition: 'border-color 0.2s, color 0.2s',
}}
onMouseEnter={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.35)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text1, #e6edf3)';
}}
onMouseLeave={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.15)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text2, #8b949e)';
}}
>
Sign out
</button>
</div>
);
}
24 changes: 21 additions & 3 deletions frontend/src/app/signin/callback/page.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,18 +7,36 @@ import { useUser } from '@/context/UserContext';
function CallbackInner() {
const searchParams = useSearchParams();
const router = useRouter();
const { setActiveUser } = useUser();
const { setActiveUser, confirmApproved } = useUser();

useEffect(() => {
const userId = searchParams.get('user_id');
const name = searchParams.get('name');
const avatar = searchParams.get('avatar');
const isApproved = searchParams.get('is_approved') === 'true';
const error = searchParams.get('error');

if (error === 'not_approved' || !isApproved) {
router.replace('/pending');
return;
}

if (userId && name) {
setActiveUser(userId, name, avatar || '');
router.replace('/');
fetch('/api/auth/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId }),
}).then(res => {
if (res.ok) {
confirmApproved();
router.replace('/dashboard');
} else {
router.replace('/signin');
}
});
} else {
router.replace('/');
router.replace('/signin');
}
}, []); // eslint-disable-line react-hooks/exhaustive-deps

Expand Down
114 changes: 114 additions & 0 deletions frontend/src/app/signin/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
'use client';

import { Suspense } from 'react';
import { useSearchParams } from 'next/navigation';
import Image from 'next/image';

const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:5000';

function SignInInner() {
const searchParams = useSearchParams();
const error = searchParams.get('error');

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>

{error === 'not_approved' && (
<div style={{
marginBottom: '24px',
padding: '12px 20px',
borderRadius: '8px',
background: 'rgba(234, 179, 8, 0.12)',
border: '1px solid rgba(234, 179, 8, 0.3)',
color: '#ca8a04',
fontSize: '14px',
textAlign: 'center',
maxWidth: '360px',
}}>
Your account is pending approval.
</div>
)}

<div style={{
background: 'var(--bg-panel, #161b22)',
border: '1px solid rgba(255,255,255,0.08)',
borderRadius: '16px',
padding: '40px',
width: '100%',
maxWidth: '380px',
}}>
<h2 style={{
fontSize: '22px',
fontWeight: 600,
color: 'var(--brand-text1, #e6edf3)',
textAlign: 'center',
marginBottom: '8px',
letterSpacing: '-0.02em',
}}>
Welcome back
</h2>
<p style={{
fontSize: '14px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
marginBottom: '28px',
}}>
Sign in to continue
</p>

<button
onClick={() => { window.location.href = `${API_URL}/api/auth/google`; }}
style={{
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '12px',
padding: '12px 20px',
background: '#ffffff',
border: '1px solid #d1d5db',
borderRadius: '10px',
fontSize: '14px',
fontWeight: 500,
color: '#111827',
cursor: 'pointer',
transition: 'box-shadow 0.2s',
}}
onMouseEnter={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = '0 2px 8px rgba(0,0,0,0.12)'; }}
onMouseLeave={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = 'none'; }}
>
<svg width="18" height="18" viewBox="0 0 24 24">
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4" />
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853" />
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05" />
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335" />
</svg>
Continue with Google
</button>
</div>
</div>
);
}

export default function SignInPage() {
return (
<Suspense fallback={<div style={{ minHeight: '100vh', background: '#0d1117' }} />}>
<SignInInner />
</Suspense>
);
}
4 changes: 2 additions & 2 deletions frontend/src/components/Navbar.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,10 +89,10 @@ export default function Navbar() {
}
};

const handleSignOut = () => {
const handleSignOut = async () => {
setMenuOpen(false);
setMobileNavOpen(false);
signOut();
await signOut();
router.push('/');
};

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/db/migration_add_is_approved.sql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS is_approved BOOLEAN NOT NULL DEFAULT false;
11 changes: 6 additions & 5 deletions backend/db/supabase_schema.sql
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,11 +10,12 @@ CREATE TABLE IF NOT EXISTS users (
email TEXT,
streak_count INTEGER DEFAULT 0,
last_active_date TEXT,
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google'
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google',
is_approved BOOLEAN NOT NULL DEFAULT false
);

CREATE INDEX IF NOT EXISTS idx_users_google_id ON users(google_id);
Expand Down
20 changes: 18 additions & 2 deletions backend/routes/auth.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,6 +68,15 @@ def _generate_pkce_pair():
return code_verifier, code_challenge


@router.get("/me")
def get_me(user_id: str = Query(...)):
"""Return approval status for a given user_id (used by Next.js session API route)."""
user = table("users").select("id,is_approved", filters={"id": f"eq.{user_id}"})
if not user:
raise HTTPException(status_code=404, detail="User not found")
return {"user_id": user_id, "is_approved": bool(user[0]["is_approved"])}


@router.get("/google")
def google_login():
"""Redirect to Google consent screen with identity + calendar scopes."""
Expand DownExpand Up@@ -117,19 +126,21 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
)

# Determine user_id: check if this Google ID already exists
existing = table("users").select("id", filters={"google_id": f"eq.{google_id}"})
existing = table("users").select("id,is_approved", filters={"google_id": f"eq.{google_id}"})
if existing:
user_id = existing[0]["id"]
is_approved = existing[0]["is_approved"]
# Update name/avatar in case they changed
table("users").update(
{"name": name, "avatar_url": avatar_url, "email": email},
filters={"id": f"eq.{user_id}"},
)
else:
# Check if a user with this email exists (migration from old system)
email_match = table("users").select("id", filters={"email": f"eq.{email}"})
email_match = table("users").select("id,is_approved", filters={"email": f"eq.{email}"})
if email_match:
user_id = email_match[0]["id"]
is_approved = email_match[0]["is_approved"]
table("users").update(
{
"google_id": google_id,
Expand All@@ -142,6 +153,7 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
else:
# Create new user
user_id = f"user_{google_id}"
is_approved = False
table("users").insert({
"id": user_id,
"name": name,
Expand All@@ -162,10 +174,14 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
on_conflict="user_id",
)

if not is_approved:
return RedirectResponse(f"{FRONTEND_URL}/pending")

# Redirect to frontend with user info
params = urlencode({
"user_id": user_id,
"name": name,
"avatar": avatar_url,
"is_approved": "true",
})
return RedirectResponse(f"{FRONTEND_URL}/signin/callback?{params}")
55 changes: 55 additions & 0 deletions frontend/src/app/api/auth/session/route.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
import { NextRequest, NextResponse } from 'next/server';
import { signSession, SESSION_MAX_AGE } from '@/lib/sessionToken';

const API_URL = process.env.NEXT_PUBLIC_API_URL;

export async function POST(request: NextRequest) {
if (!API_URL) {
return NextResponse.json({ error: 'NEXT_PUBLIC_API_URL not configured' }, { status: 500 });
}

const { userId } = await request.json();
if (!userId || typeof userId !== 'string') {
return NextResponse.json({ error: 'Missing userId' }, { status: 400 });
}

// Verify with the backend that the user exists and is approved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove the obvious inline comment to match repo style.

Line 12 explains directly-following code and is not non-obvious logic.

As per coding guidelines, "No docstrings or comments unless the logic is non-obvious".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@frontend/src/app/api/auth/session/route.ts` at line 12, Remove the inline
comment "// Verify with the backend that the user exists and is approved." from
the session route handler code (the comment directly above the backend
user/approval verification block) so the file no longer contains
obvious-following-code comments; leave the surrounding verification logic (the
handler/function that performs the backend user existence/approval check)
unchanged.

let approved = false;
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 3000);
let res: Response;
try {
res = await fetch(`${API_URL}/auth/me?user_id=${encodeURIComponent(userId)}`, { signal: controller.signal });
} finally {
clearTimeout(timeout);
}
if (!res.ok) {
return NextResponse.json({ error: 'User not found' }, { status: 401 });
}
const data = await res.json();
approved = data.is_approved === true;
} catch {
return NextResponse.json({ error: 'Backend unreachable' }, { status: 502 });
}

if (!approved) {
return NextResponse.json({ error: 'Not approved' }, { status: 403 });
}

const token = await signSession(userId);
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', token, {
httpOnly: true,
sameSite: 'lax',
path: '/',
maxAge: SESSION_MAX_AGE,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return response;
}

export async function DELETE() {
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', '', { httpOnly: true, maxAge: 0, path: '/' });
return response;
}
78 changes: 78 additions & 0 deletions frontend/src/app/pending/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
'use client';

import { useRouter } from 'next/navigation';
import Image from 'next/image';
import { useUser } from '@/context/UserContext';

export default function PendingPage() {
const router = useRouter();
const { signOut } = useUser();

async function handleSignOut() {
await signOut();
router.replace('/signin');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
color: 'var(--brand-text1, #e6edf3)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>
<h1 style={{
fontSize: '28px',
fontWeight: 600,
marginBottom: '12px',
textAlign: 'center',
letterSpacing: '-0.02em',
}}>
You&apos;re on the waitlist
</h1>
<p style={{
fontSize: '15px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
maxWidth: '340px',
lineHeight: 1.6,
marginBottom: '40px',
}}>
We&apos;ll reach out when your access is approved.
</p>
<button
onClick={handleSignOut}
style={{
background: 'transparent',
border: '1px solid rgba(255,255,255,0.15)',
color: 'var(--brand-text2, #8b949e)',
padding: '10px 24px',
borderRadius: '8px',
fontSize: '14px',
cursor: 'pointer',
transition: 'border-color 0.2s, color 0.2s',
}}
onMouseEnter={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.35)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text1, #e6edf3)';
}}
onMouseLeave={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.15)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text2, #8b949e)';
}}
>
Sign out
</button>
</div>
);
}
24 changes: 21 additions & 3 deletions frontend/src/app/signin/callback/page.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,18 +7,36 @@ import { useUser } from '@/context/UserContext';
function CallbackInner() {
const searchParams = useSearchParams();
const router = useRouter();
const { setActiveUser } = useUser();
const { setActiveUser, confirmApproved } = useUser();

useEffect(() => {
const userId = searchParams.get('user_id');
const name = searchParams.get('name');
const avatar = searchParams.get('avatar');
const isApproved = searchParams.get('is_approved') === 'true';
const error = searchParams.get('error');

if (error === 'not_approved' || !isApproved) {
router.replace('/pending');
return;
}

if (userId && name) {
setActiveUser(userId, name, avatar || '');
router.replace('/');
fetch('/api/auth/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId }),
}).then(res => {
if (res.ok) {
confirmApproved();
router.replace('/dashboard');
} else {
router.replace('/signin');
}
});
} else {
router.replace('/');
router.replace('/signin');
}
}, []); // eslint-disable-line react-hooks/exhaustive-deps

Expand Down
114 changes: 114 additions & 0 deletions frontend/src/app/signin/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
'use client';

import { Suspense } from 'react';
import { useSearchParams } from 'next/navigation';
import Image from 'next/image';

const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:5000';

function SignInInner() {
const searchParams = useSearchParams();
const error = searchParams.get('error');

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>

{error === 'not_approved' && (
<div style={{
marginBottom: '24px',
padding: '12px 20px',
borderRadius: '8px',
background: 'rgba(234, 179, 8, 0.12)',
border: '1px solid rgba(234, 179, 8, 0.3)',
color: '#ca8a04',
fontSize: '14px',
textAlign: 'center',
maxWidth: '360px',
}}>
Your account is pending approval.
</div>
)}

<div style={{
background: 'var(--bg-panel, #161b22)',
border: '1px solid rgba(255,255,255,0.08)',
borderRadius: '16px',
padding: '40px',
width: '100%',
maxWidth: '380px',
}}>
<h2 style={{
fontSize: '22px',
fontWeight: 600,
color: 'var(--brand-text1, #e6edf3)',
textAlign: 'center',
marginBottom: '8px',
letterSpacing: '-0.02em',
}}>
Welcome back
</h2>
<p style={{
fontSize: '14px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
marginBottom: '28px',
}}>
Sign in to continue
</p>

<button
onClick={() => { window.location.href = `${API_URL}/api/auth/google`; }}
style={{
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '12px',
padding: '12px 20px',
background: '#ffffff',
border: '1px solid #d1d5db',
borderRadius: '10px',
fontSize: '14px',
fontWeight: 500,
color: '#111827',
cursor: 'pointer',
transition: 'box-shadow 0.2s',
}}
onMouseEnter={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = '0 2px 8px rgba(0,0,0,0.12)'; }}
onMouseLeave={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = 'none'; }}
>
<svg width="18" height="18" viewBox="0 0 24 24">
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4" />
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853" />
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05" />
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335" />
</svg>
Continue with Google
</button>
</div>
</div>
);
}

export default function SignInPage() {
return (
<Suspense fallback={<div style={{ minHeight: '100vh', background: '#0d1117' }} />}>
<SignInInner />
</Suspense>
);
}
4 changes: 2 additions & 2 deletions frontend/src/components/Navbar.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,10 +89,10 @@ export default function Navbar() {
}
};

const handleSignOut = () => {
const handleSignOut = async () => {
setMenuOpen(false);
setMobileNavOpen(false);
signOut();
await signOut();
router.push('/');
};

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/db/migration_add_is_approved.sql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS is_approved BOOLEAN NOT NULL DEFAULT false;
11 changes: 6 additions & 5 deletions backend/db/supabase_schema.sql
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,11 +10,12 @@ CREATE TABLE IF NOT EXISTS users (
email TEXT,
streak_count INTEGER DEFAULT 0,
last_active_date TEXT,
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google'
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google',
is_approved BOOLEAN NOT NULL DEFAULT false
);

CREATE INDEX IF NOT EXISTS idx_users_google_id ON users(google_id);
Expand Down
20 changes: 18 additions & 2 deletions backend/routes/auth.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,6 +68,15 @@ def _generate_pkce_pair():
return code_verifier, code_challenge


@router.get("/me")
def get_me(user_id: str = Query(...)):
"""Return approval status for a given user_id (used by Next.js session API route)."""
user = table("users").select("id,is_approved", filters={"id": f"eq.{user_id}"})
if not user:
raise HTTPException(status_code=404, detail="User not found")
return {"user_id": user_id, "is_approved": bool(user[0]["is_approved"])}


@router.get("/google")
def google_login():
"""Redirect to Google consent screen with identity + calendar scopes."""
Expand DownExpand Up@@ -117,19 +126,21 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
)

# Determine user_id: check if this Google ID already exists
existing = table("users").select("id", filters={"google_id": f"eq.{google_id}"})
existing = table("users").select("id,is_approved", filters={"google_id": f"eq.{google_id}"})
if existing:
user_id = existing[0]["id"]
is_approved = existing[0]["is_approved"]
# Update name/avatar in case they changed
table("users").update(
{"name": name, "avatar_url": avatar_url, "email": email},
filters={"id": f"eq.{user_id}"},
)
else:
# Check if a user with this email exists (migration from old system)
email_match = table("users").select("id", filters={"email": f"eq.{email}"})
email_match = table("users").select("id,is_approved", filters={"email": f"eq.{email}"})
if email_match:
user_id = email_match[0]["id"]
is_approved = email_match[0]["is_approved"]
table("users").update(
{
"google_id": google_id,
Expand All@@ -142,6 +153,7 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
else:
# Create new user
user_id = f"user_{google_id}"
is_approved = False
table("users").insert({
"id": user_id,
"name": name,
Expand All@@ -162,10 +174,14 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
on_conflict="user_id",
)

if not is_approved:
return RedirectResponse(f"{FRONTEND_URL}/pending")

# Redirect to frontend with user info
params = urlencode({
"user_id": user_id,
"name": name,
"avatar": avatar_url,
"is_approved": "true",
})
return RedirectResponse(f"{FRONTEND_URL}/signin/callback?{params}")
55 changes: 55 additions & 0 deletions frontend/src/app/api/auth/session/route.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
import { NextRequest, NextResponse } from 'next/server';
import { signSession, SESSION_MAX_AGE } from '@/lib/sessionToken';

const API_URL = process.env.NEXT_PUBLIC_API_URL;

export async function POST(request: NextRequest) {
if (!API_URL) {
return NextResponse.json({ error: 'NEXT_PUBLIC_API_URL not configured' }, { status: 500 });
}

const { userId } = await request.json();
if (!userId || typeof userId !== 'string') {
return NextResponse.json({ error: 'Missing userId' }, { status: 400 });
}

// Verify with the backend that the user exists and is approved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove the obvious inline comment to match repo style.

Line 12 explains directly-following code and is not non-obvious logic.

As per coding guidelines, "No docstrings or comments unless the logic is non-obvious".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@frontend/src/app/api/auth/session/route.ts` at line 12, Remove the inline
comment "// Verify with the backend that the user exists and is approved." from
the session route handler code (the comment directly above the backend
user/approval verification block) so the file no longer contains
obvious-following-code comments; leave the surrounding verification logic (the
handler/function that performs the backend user existence/approval check)
unchanged.

let approved = false;
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 3000);
let res: Response;
try {
res = await fetch(`${API_URL}/auth/me?user_id=${encodeURIComponent(userId)}`, { signal: controller.signal });
} finally {
clearTimeout(timeout);
}
if (!res.ok) {
return NextResponse.json({ error: 'User not found' }, { status: 401 });
}
const data = await res.json();
approved = data.is_approved === true;
} catch {
return NextResponse.json({ error: 'Backend unreachable' }, { status: 502 });
}

if (!approved) {
return NextResponse.json({ error: 'Not approved' }, { status: 403 });
}

const token = await signSession(userId);
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', token, {
httpOnly: true,
sameSite: 'lax',
path: '/',
maxAge: SESSION_MAX_AGE,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return response;
}

export async function DELETE() {
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', '', { httpOnly: true, maxAge: 0, path: '/' });
return response;
}
78 changes: 78 additions & 0 deletions frontend/src/app/pending/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
'use client';

import { useRouter } from 'next/navigation';
import Image from 'next/image';
import { useUser } from '@/context/UserContext';

export default function PendingPage() {
const router = useRouter();
const { signOut } = useUser();

async function handleSignOut() {
await signOut();
router.replace('/signin');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
color: 'var(--brand-text1, #e6edf3)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>
<h1 style={{
fontSize: '28px',
fontWeight: 600,
marginBottom: '12px',
textAlign: 'center',
letterSpacing: '-0.02em',
}}>
You&apos;re on the waitlist
</h1>
<p style={{
fontSize: '15px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
maxWidth: '340px',
lineHeight: 1.6,
marginBottom: '40px',
}}>
We&apos;ll reach out when your access is approved.
</p>
<button
onClick={handleSignOut}
style={{
background: 'transparent',
border: '1px solid rgba(255,255,255,0.15)',
color: 'var(--brand-text2, #8b949e)',
padding: '10px 24px',
borderRadius: '8px',
fontSize: '14px',
cursor: 'pointer',
transition: 'border-color 0.2s, color 0.2s',
}}
onMouseEnter={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.35)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text1, #e6edf3)';
}}
onMouseLeave={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.15)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text2, #8b949e)';
}}
>
Sign out
</button>
</div>
);
}
24 changes: 21 additions & 3 deletions frontend/src/app/signin/callback/page.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,18 +7,36 @@ import { useUser } from '@/context/UserContext';
function CallbackInner() {
const searchParams = useSearchParams();
const router = useRouter();
const { setActiveUser } = useUser();
const { setActiveUser, confirmApproved } = useUser();

useEffect(() => {
const userId = searchParams.get('user_id');
const name = searchParams.get('name');
const avatar = searchParams.get('avatar');
const isApproved = searchParams.get('is_approved') === 'true';
const error = searchParams.get('error');

if (error === 'not_approved' || !isApproved) {
router.replace('/pending');
return;
}

if (userId && name) {
setActiveUser(userId, name, avatar || '');
router.replace('/');
fetch('/api/auth/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId }),
}).then(res => {
if (res.ok) {
confirmApproved();
router.replace('/dashboard');
} else {
router.replace('/signin');
}
});
} else {
router.replace('/');
router.replace('/signin');
}
}, []); // eslint-disable-line react-hooks/exhaustive-deps

Expand Down
114 changes: 114 additions & 0 deletions frontend/src/app/signin/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
'use client';

import { Suspense } from 'react';
import { useSearchParams } from 'next/navigation';
import Image from 'next/image';

const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:5000';

function SignInInner() {
const searchParams = useSearchParams();
const error = searchParams.get('error');

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>

{error === 'not_approved' && (
<div style={{
marginBottom: '24px',
padding: '12px 20px',
borderRadius: '8px',
background: 'rgba(234, 179, 8, 0.12)',
border: '1px solid rgba(234, 179, 8, 0.3)',
color: '#ca8a04',
fontSize: '14px',
textAlign: 'center',
maxWidth: '360px',
}}>
Your account is pending approval.
</div>
)}

<div style={{
background: 'var(--bg-panel, #161b22)',
border: '1px solid rgba(255,255,255,0.08)',
borderRadius: '16px',
padding: '40px',
width: '100%',
maxWidth: '380px',
}}>
<h2 style={{
fontSize: '22px',
fontWeight: 600,
color: 'var(--brand-text1, #e6edf3)',
textAlign: 'center',
marginBottom: '8px',
letterSpacing: '-0.02em',
}}>
Welcome back
</h2>
<p style={{
fontSize: '14px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
marginBottom: '28px',
}}>
Sign in to continue
</p>

<button
onClick={() => { window.location.href = `${API_URL}/api/auth/google`; }}
style={{
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '12px',
padding: '12px 20px',
background: '#ffffff',
border: '1px solid #d1d5db',
borderRadius: '10px',
fontSize: '14px',
fontWeight: 500,
color: '#111827',
cursor: 'pointer',
transition: 'box-shadow 0.2s',
}}
onMouseEnter={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = '0 2px 8px rgba(0,0,0,0.12)'; }}
onMouseLeave={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = 'none'; }}
>
<svg width="18" height="18" viewBox="0 0 24 24">
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4" />
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853" />
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05" />
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335" />
</svg>
Continue with Google
</button>
</div>
</div>
);
}

export default function SignInPage() {
return (
<Suspense fallback={<div style={{ minHeight: '100vh', background: '#0d1117' }} />}>
<SignInInner />
</Suspense>
);
}
4 changes: 2 additions & 2 deletions frontend/src/components/Navbar.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,10 +89,10 @@ export default function Navbar() {
}
};

const handleSignOut = () => {
const handleSignOut = async () => {
setMenuOpen(false);
setMobileNavOpen(false);
signOut();
await signOut();
router.push('/');
};

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/db/migration_add_is_approved.sql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS is_approved BOOLEAN NOT NULL DEFAULT false;
11 changes: 6 additions & 5 deletions backend/db/supabase_schema.sql
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,11 +10,12 @@ CREATE TABLE IF NOT EXISTS users (
email TEXT,
streak_count INTEGER DEFAULT 0,
last_active_date TEXT,
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google'
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google',
is_approved BOOLEAN NOT NULL DEFAULT false
);

CREATE INDEX IF NOT EXISTS idx_users_google_id ON users(google_id);
Expand Down
20 changes: 18 additions & 2 deletions backend/routes/auth.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,6 +68,15 @@ def _generate_pkce_pair():
return code_verifier, code_challenge


@router.get("/me")
def get_me(user_id: str = Query(...)):
"""Return approval status for a given user_id (used by Next.js session API route)."""
user = table("users").select("id,is_approved", filters={"id": f"eq.{user_id}"})
if not user:
raise HTTPException(status_code=404, detail="User not found")
return {"user_id": user_id, "is_approved": bool(user[0]["is_approved"])}


@router.get("/google")
def google_login():
"""Redirect to Google consent screen with identity + calendar scopes."""
Expand DownExpand Up@@ -117,19 +126,21 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
)

# Determine user_id: check if this Google ID already exists
existing = table("users").select("id", filters={"google_id": f"eq.{google_id}"})
existing = table("users").select("id,is_approved", filters={"google_id": f"eq.{google_id}"})
if existing:
user_id = existing[0]["id"]
is_approved = existing[0]["is_approved"]
# Update name/avatar in case they changed
table("users").update(
{"name": name, "avatar_url": avatar_url, "email": email},
filters={"id": f"eq.{user_id}"},
)
else:
# Check if a user with this email exists (migration from old system)
email_match = table("users").select("id", filters={"email": f"eq.{email}"})
email_match = table("users").select("id,is_approved", filters={"email": f"eq.{email}"})
if email_match:
user_id = email_match[0]["id"]
is_approved = email_match[0]["is_approved"]
table("users").update(
{
"google_id": google_id,
Expand All@@ -142,6 +153,7 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
else:
# Create new user
user_id = f"user_{google_id}"
is_approved = False
table("users").insert({
"id": user_id,
"name": name,
Expand All@@ -162,10 +174,14 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
on_conflict="user_id",
)

if not is_approved:
return RedirectResponse(f"{FRONTEND_URL}/pending")

# Redirect to frontend with user info
params = urlencode({
"user_id": user_id,
"name": name,
"avatar": avatar_url,
"is_approved": "true",
})
return RedirectResponse(f"{FRONTEND_URL}/signin/callback?{params}")
55 changes: 55 additions & 0 deletions frontend/src/app/api/auth/session/route.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
import { NextRequest, NextResponse } from 'next/server';
import { signSession, SESSION_MAX_AGE } from '@/lib/sessionToken';

const API_URL = process.env.NEXT_PUBLIC_API_URL;

export async function POST(request: NextRequest) {
if (!API_URL) {
return NextResponse.json({ error: 'NEXT_PUBLIC_API_URL not configured' }, { status: 500 });
}

const { userId } = await request.json();
if (!userId || typeof userId !== 'string') {
return NextResponse.json({ error: 'Missing userId' }, { status: 400 });
}

// Verify with the backend that the user exists and is approved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove the obvious inline comment to match repo style.

Line 12 explains directly-following code and is not non-obvious logic.

As per coding guidelines, "No docstrings or comments unless the logic is non-obvious".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@frontend/src/app/api/auth/session/route.ts` at line 12, Remove the inline
comment "// Verify with the backend that the user exists and is approved." from
the session route handler code (the comment directly above the backend
user/approval verification block) so the file no longer contains
obvious-following-code comments; leave the surrounding verification logic (the
handler/function that performs the backend user existence/approval check)
unchanged.

let approved = false;
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 3000);
let res: Response;
try {
res = await fetch(`${API_URL}/auth/me?user_id=${encodeURIComponent(userId)}`, { signal: controller.signal });
} finally {
clearTimeout(timeout);
}
if (!res.ok) {
return NextResponse.json({ error: 'User not found' }, { status: 401 });
}
const data = await res.json();
approved = data.is_approved === true;
} catch {
return NextResponse.json({ error: 'Backend unreachable' }, { status: 502 });
}

if (!approved) {
return NextResponse.json({ error: 'Not approved' }, { status: 403 });
}

const token = await signSession(userId);
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', token, {
httpOnly: true,
sameSite: 'lax',
path: '/',
maxAge: SESSION_MAX_AGE,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return response;
}

export async function DELETE() {
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', '', { httpOnly: true, maxAge: 0, path: '/' });
return response;
}
78 changes: 78 additions & 0 deletions frontend/src/app/pending/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
'use client';

import { useRouter } from 'next/navigation';
import Image from 'next/image';
import { useUser } from '@/context/UserContext';

export default function PendingPage() {
const router = useRouter();
const { signOut } = useUser();

async function handleSignOut() {
await signOut();
router.replace('/signin');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
color: 'var(--brand-text1, #e6edf3)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>
<h1 style={{
fontSize: '28px',
fontWeight: 600,
marginBottom: '12px',
textAlign: 'center',
letterSpacing: '-0.02em',
}}>
You&apos;re on the waitlist
</h1>
<p style={{
fontSize: '15px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
maxWidth: '340px',
lineHeight: 1.6,
marginBottom: '40px',
}}>
We&apos;ll reach out when your access is approved.
</p>
<button
onClick={handleSignOut}
style={{
background: 'transparent',
border: '1px solid rgba(255,255,255,0.15)',
color: 'var(--brand-text2, #8b949e)',
padding: '10px 24px',
borderRadius: '8px',
fontSize: '14px',
cursor: 'pointer',
transition: 'border-color 0.2s, color 0.2s',
}}
onMouseEnter={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.35)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text1, #e6edf3)';
}}
onMouseLeave={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.15)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text2, #8b949e)';
}}
>
Sign out
</button>
</div>
);
}
24 changes: 21 additions & 3 deletions frontend/src/app/signin/callback/page.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,18 +7,36 @@ import { useUser } from '@/context/UserContext';
function CallbackInner() {
const searchParams = useSearchParams();
const router = useRouter();
const { setActiveUser } = useUser();
const { setActiveUser, confirmApproved } = useUser();

useEffect(() => {
const userId = searchParams.get('user_id');
const name = searchParams.get('name');
const avatar = searchParams.get('avatar');
const isApproved = searchParams.get('is_approved') === 'true';
const error = searchParams.get('error');

if (error === 'not_approved' || !isApproved) {
router.replace('/pending');
return;
}

if (userId && name) {
setActiveUser(userId, name, avatar || '');
router.replace('/');
fetch('/api/auth/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId }),
}).then(res => {
if (res.ok) {
confirmApproved();
router.replace('/dashboard');
} else {
router.replace('/signin');
}
});
} else {
router.replace('/');
router.replace('/signin');
}
}, []); // eslint-disable-line react-hooks/exhaustive-deps

Expand Down
114 changes: 114 additions & 0 deletions frontend/src/app/signin/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
'use client';

import { Suspense } from 'react';
import { useSearchParams } from 'next/navigation';
import Image from 'next/image';

const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:5000';

function SignInInner() {
const searchParams = useSearchParams();
const error = searchParams.get('error');

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>

{error === 'not_approved' && (
<div style={{
marginBottom: '24px',
padding: '12px 20px',
borderRadius: '8px',
background: 'rgba(234, 179, 8, 0.12)',
border: '1px solid rgba(234, 179, 8, 0.3)',
color: '#ca8a04',
fontSize: '14px',
textAlign: 'center',
maxWidth: '360px',
}}>
Your account is pending approval.
</div>
)}

<div style={{
background: 'var(--bg-panel, #161b22)',
border: '1px solid rgba(255,255,255,0.08)',
borderRadius: '16px',
padding: '40px',
width: '100%',
maxWidth: '380px',
}}>
<h2 style={{
fontSize: '22px',
fontWeight: 600,
color: 'var(--brand-text1, #e6edf3)',
textAlign: 'center',
marginBottom: '8px',
letterSpacing: '-0.02em',
}}>
Welcome back
</h2>
<p style={{
fontSize: '14px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
marginBottom: '28px',
}}>
Sign in to continue
</p>

<button
onClick={() => { window.location.href = `${API_URL}/api/auth/google`; }}
style={{
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '12px',
padding: '12px 20px',
background: '#ffffff',
border: '1px solid #d1d5db',
borderRadius: '10px',
fontSize: '14px',
fontWeight: 500,
color: '#111827',
cursor: 'pointer',
transition: 'box-shadow 0.2s',
}}
onMouseEnter={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = '0 2px 8px rgba(0,0,0,0.12)'; }}
onMouseLeave={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = 'none'; }}
>
<svg width="18" height="18" viewBox="0 0 24 24">
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4" />
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853" />
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05" />
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335" />
</svg>
Continue with Google
</button>
</div>
</div>
);
}

export default function SignInPage() {
return (
<Suspense fallback={<div style={{ minHeight: '100vh', background: '#0d1117' }} />}>
<SignInInner />
</Suspense>
);
}
4 changes: 2 additions & 2 deletions frontend/src/components/Navbar.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,10 +89,10 @@ export default function Navbar() {
}
};

const handleSignOut = () => {
const handleSignOut = async () => {
setMenuOpen(false);
setMobileNavOpen(false);
signOut();
await signOut();
router.push('/');
};

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/db/migration_add_is_approved.sql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS is_approved BOOLEAN NOT NULL DEFAULT false;
11 changes: 6 additions & 5 deletions backend/db/supabase_schema.sql
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,11 +10,12 @@ CREATE TABLE IF NOT EXISTS users (
email TEXT,
streak_count INTEGER DEFAULT 0,
last_active_date TEXT,
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google'
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google',
is_approved BOOLEAN NOT NULL DEFAULT false
);

CREATE INDEX IF NOT EXISTS idx_users_google_id ON users(google_id);
Expand Down
20 changes: 18 additions & 2 deletions backend/routes/auth.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,6 +68,15 @@ def _generate_pkce_pair():
return code_verifier, code_challenge


@router.get("/me")
def get_me(user_id: str = Query(...)):
"""Return approval status for a given user_id (used by Next.js session API route)."""
user = table("users").select("id,is_approved", filters={"id": f"eq.{user_id}"})
if not user:
raise HTTPException(status_code=404, detail="User not found")
return {"user_id": user_id, "is_approved": bool(user[0]["is_approved"])}


@router.get("/google")
def google_login():
"""Redirect to Google consent screen with identity + calendar scopes."""
Expand DownExpand Up@@ -117,19 +126,21 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
)

# Determine user_id: check if this Google ID already exists
existing = table("users").select("id", filters={"google_id": f"eq.{google_id}"})
existing = table("users").select("id,is_approved", filters={"google_id": f"eq.{google_id}"})
if existing:
user_id = existing[0]["id"]
is_approved = existing[0]["is_approved"]
# Update name/avatar in case they changed
table("users").update(
{"name": name, "avatar_url": avatar_url, "email": email},
filters={"id": f"eq.{user_id}"},
)
else:
# Check if a user with this email exists (migration from old system)
email_match = table("users").select("id", filters={"email": f"eq.{email}"})
email_match = table("users").select("id,is_approved", filters={"email": f"eq.{email}"})
if email_match:
user_id = email_match[0]["id"]
is_approved = email_match[0]["is_approved"]
table("users").update(
{
"google_id": google_id,
Expand All@@ -142,6 +153,7 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
else:
# Create new user
user_id = f"user_{google_id}"
is_approved = False
table("users").insert({
"id": user_id,
"name": name,
Expand All@@ -162,10 +174,14 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
on_conflict="user_id",
)

if not is_approved:
return RedirectResponse(f"{FRONTEND_URL}/pending")

# Redirect to frontend with user info
params = urlencode({
"user_id": user_id,
"name": name,
"avatar": avatar_url,
"is_approved": "true",
})
return RedirectResponse(f"{FRONTEND_URL}/signin/callback?{params}")
55 changes: 55 additions & 0 deletions frontend/src/app/api/auth/session/route.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
import { NextRequest, NextResponse } from 'next/server';
import { signSession, SESSION_MAX_AGE } from '@/lib/sessionToken';

const API_URL = process.env.NEXT_PUBLIC_API_URL;

export async function POST(request: NextRequest) {
if (!API_URL) {
return NextResponse.json({ error: 'NEXT_PUBLIC_API_URL not configured' }, { status: 500 });
}

const { userId } = await request.json();
if (!userId || typeof userId !== 'string') {
return NextResponse.json({ error: 'Missing userId' }, { status: 400 });
}

// Verify with the backend that the user exists and is approved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove the obvious inline comment to match repo style.

Line 12 explains directly-following code and is not non-obvious logic.

As per coding guidelines, "No docstrings or comments unless the logic is non-obvious".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@frontend/src/app/api/auth/session/route.ts` at line 12, Remove the inline
comment "// Verify with the backend that the user exists and is approved." from
the session route handler code (the comment directly above the backend
user/approval verification block) so the file no longer contains
obvious-following-code comments; leave the surrounding verification logic (the
handler/function that performs the backend user existence/approval check)
unchanged.

let approved = false;
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 3000);
let res: Response;
try {
res = await fetch(`${API_URL}/auth/me?user_id=${encodeURIComponent(userId)}`, { signal: controller.signal });
} finally {
clearTimeout(timeout);
}
if (!res.ok) {
return NextResponse.json({ error: 'User not found' }, { status: 401 });
}
const data = await res.json();
approved = data.is_approved === true;
} catch {
return NextResponse.json({ error: 'Backend unreachable' }, { status: 502 });
}

if (!approved) {
return NextResponse.json({ error: 'Not approved' }, { status: 403 });
}

const token = await signSession(userId);
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', token, {
httpOnly: true,
sameSite: 'lax',
path: '/',
maxAge: SESSION_MAX_AGE,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return response;
}

export async function DELETE() {
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', '', { httpOnly: true, maxAge: 0, path: '/' });
return response;
}
78 changes: 78 additions & 0 deletions frontend/src/app/pending/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
'use client';

import { useRouter } from 'next/navigation';
import Image from 'next/image';
import { useUser } from '@/context/UserContext';

export default function PendingPage() {
const router = useRouter();
const { signOut } = useUser();

async function handleSignOut() {
await signOut();
router.replace('/signin');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
color: 'var(--brand-text1, #e6edf3)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>
<h1 style={{
fontSize: '28px',
fontWeight: 600,
marginBottom: '12px',
textAlign: 'center',
letterSpacing: '-0.02em',
}}>
You&apos;re on the waitlist
</h1>
<p style={{
fontSize: '15px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
maxWidth: '340px',
lineHeight: 1.6,
marginBottom: '40px',
}}>
We&apos;ll reach out when your access is approved.
</p>
<button
onClick={handleSignOut}
style={{
background: 'transparent',
border: '1px solid rgba(255,255,255,0.15)',
color: 'var(--brand-text2, #8b949e)',
padding: '10px 24px',
borderRadius: '8px',
fontSize: '14px',
cursor: 'pointer',
transition: 'border-color 0.2s, color 0.2s',
}}
onMouseEnter={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.35)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text1, #e6edf3)';
}}
onMouseLeave={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.15)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text2, #8b949e)';
}}
>
Sign out
</button>
</div>
);
}
24 changes: 21 additions & 3 deletions frontend/src/app/signin/callback/page.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,18 +7,36 @@ import { useUser } from '@/context/UserContext';
function CallbackInner() {
const searchParams = useSearchParams();
const router = useRouter();
const { setActiveUser } = useUser();
const { setActiveUser, confirmApproved } = useUser();

useEffect(() => {
const userId = searchParams.get('user_id');
const name = searchParams.get('name');
const avatar = searchParams.get('avatar');
const isApproved = searchParams.get('is_approved') === 'true';
const error = searchParams.get('error');

if (error === 'not_approved' || !isApproved) {
router.replace('/pending');
return;
}

if (userId && name) {
setActiveUser(userId, name, avatar || '');
router.replace('/');
fetch('/api/auth/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId }),
}).then(res => {
if (res.ok) {
confirmApproved();
router.replace('/dashboard');
} else {
router.replace('/signin');
}
});
} else {
router.replace('/');
router.replace('/signin');
}
}, []); // eslint-disable-line react-hooks/exhaustive-deps

Expand Down
114 changes: 114 additions & 0 deletions frontend/src/app/signin/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
'use client';

import { Suspense } from 'react';
import { useSearchParams } from 'next/navigation';
import Image from 'next/image';

const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:5000';

function SignInInner() {
const searchParams = useSearchParams();
const error = searchParams.get('error');

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>

{error === 'not_approved' && (
<div style={{
marginBottom: '24px',
padding: '12px 20px',
borderRadius: '8px',
background: 'rgba(234, 179, 8, 0.12)',
border: '1px solid rgba(234, 179, 8, 0.3)',
color: '#ca8a04',
fontSize: '14px',
textAlign: 'center',
maxWidth: '360px',
}}>
Your account is pending approval.
</div>
)}

<div style={{
background: 'var(--bg-panel, #161b22)',
border: '1px solid rgba(255,255,255,0.08)',
borderRadius: '16px',
padding: '40px',
width: '100%',
maxWidth: '380px',
}}>
<h2 style={{
fontSize: '22px',
fontWeight: 600,
color: 'var(--brand-text1, #e6edf3)',
textAlign: 'center',
marginBottom: '8px',
letterSpacing: '-0.02em',
}}>
Welcome back
</h2>
<p style={{
fontSize: '14px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
marginBottom: '28px',
}}>
Sign in to continue
</p>

<button
onClick={() => { window.location.href = `${API_URL}/api/auth/google`; }}
style={{
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '12px',
padding: '12px 20px',
background: '#ffffff',
border: '1px solid #d1d5db',
borderRadius: '10px',
fontSize: '14px',
fontWeight: 500,
color: '#111827',
cursor: 'pointer',
transition: 'box-shadow 0.2s',
}}
onMouseEnter={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = '0 2px 8px rgba(0,0,0,0.12)'; }}
onMouseLeave={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = 'none'; }}
>
<svg width="18" height="18" viewBox="0 0 24 24">
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4" />
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853" />
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05" />
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335" />
</svg>
Continue with Google
</button>
</div>
</div>
);
}

export default function SignInPage() {
return (
<Suspense fallback={<div style={{ minHeight: '100vh', background: '#0d1117' }} />}>
<SignInInner />
</Suspense>
);
}
4 changes: 2 additions & 2 deletions frontend/src/components/Navbar.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,10 +89,10 @@ export default function Navbar() {
}
};

const handleSignOut = () => {
const handleSignOut = async () => {
setMenuOpen(false);
setMobileNavOpen(false);
signOut();
await signOut();
router.push('/');
};

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/db/migration_add_is_approved.sql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS is_approved BOOLEAN NOT NULL DEFAULT false;
11 changes: 6 additions & 5 deletions backend/db/supabase_schema.sql
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,11 +10,12 @@ CREATE TABLE IF NOT EXISTS users (
email TEXT,
streak_count INTEGER DEFAULT 0,
last_active_date TEXT,
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google'
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google',
is_approved BOOLEAN NOT NULL DEFAULT false
);

CREATE INDEX IF NOT EXISTS idx_users_google_id ON users(google_id);
Expand Down
20 changes: 18 additions & 2 deletions backend/routes/auth.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,6 +68,15 @@ def _generate_pkce_pair():
return code_verifier, code_challenge


@router.get("/me")
def get_me(user_id: str = Query(...)):
"""Return approval status for a given user_id (used by Next.js session API route)."""
user = table("users").select("id,is_approved", filters={"id": f"eq.{user_id}"})
if not user:
raise HTTPException(status_code=404, detail="User not found")
return {"user_id": user_id, "is_approved": bool(user[0]["is_approved"])}


@router.get("/google")
def google_login():
"""Redirect to Google consent screen with identity + calendar scopes."""
Expand DownExpand Up@@ -117,19 +126,21 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
)

# Determine user_id: check if this Google ID already exists
existing = table("users").select("id", filters={"google_id": f"eq.{google_id}"})
existing = table("users").select("id,is_approved", filters={"google_id": f"eq.{google_id}"})
if existing:
user_id = existing[0]["id"]
is_approved = existing[0]["is_approved"]
# Update name/avatar in case they changed
table("users").update(
{"name": name, "avatar_url": avatar_url, "email": email},
filters={"id": f"eq.{user_id}"},
)
else:
# Check if a user with this email exists (migration from old system)
email_match = table("users").select("id", filters={"email": f"eq.{email}"})
email_match = table("users").select("id,is_approved", filters={"email": f"eq.{email}"})
if email_match:
user_id = email_match[0]["id"]
is_approved = email_match[0]["is_approved"]
table("users").update(
{
"google_id": google_id,
Expand All@@ -142,6 +153,7 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
else:
# Create new user
user_id = f"user_{google_id}"
is_approved = False
table("users").insert({
"id": user_id,
"name": name,
Expand All@@ -162,10 +174,14 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
on_conflict="user_id",
)

if not is_approved:
return RedirectResponse(f"{FRONTEND_URL}/pending")

# Redirect to frontend with user info
params = urlencode({
"user_id": user_id,
"name": name,
"avatar": avatar_url,
"is_approved": "true",
})
return RedirectResponse(f"{FRONTEND_URL}/signin/callback?{params}")
55 changes: 55 additions & 0 deletions frontend/src/app/api/auth/session/route.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
import { NextRequest, NextResponse } from 'next/server';
import { signSession, SESSION_MAX_AGE } from '@/lib/sessionToken';

const API_URL = process.env.NEXT_PUBLIC_API_URL;

export async function POST(request: NextRequest) {
if (!API_URL) {
return NextResponse.json({ error: 'NEXT_PUBLIC_API_URL not configured' }, { status: 500 });
}

const { userId } = await request.json();
if (!userId || typeof userId !== 'string') {
return NextResponse.json({ error: 'Missing userId' }, { status: 400 });
}

// Verify with the backend that the user exists and is approved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove the obvious inline comment to match repo style.

Line 12 explains directly-following code and is not non-obvious logic.

As per coding guidelines, "No docstrings or comments unless the logic is non-obvious".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@frontend/src/app/api/auth/session/route.ts` at line 12, Remove the inline
comment "// Verify with the backend that the user exists and is approved." from
the session route handler code (the comment directly above the backend
user/approval verification block) so the file no longer contains
obvious-following-code comments; leave the surrounding verification logic (the
handler/function that performs the backend user existence/approval check)
unchanged.

let approved = false;
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 3000);
let res: Response;
try {
res = await fetch(`${API_URL}/auth/me?user_id=${encodeURIComponent(userId)}`, { signal: controller.signal });
} finally {
clearTimeout(timeout);
}
if (!res.ok) {
return NextResponse.json({ error: 'User not found' }, { status: 401 });
}
const data = await res.json();
approved = data.is_approved === true;
} catch {
return NextResponse.json({ error: 'Backend unreachable' }, { status: 502 });
}

if (!approved) {
return NextResponse.json({ error: 'Not approved' }, { status: 403 });
}

const token = await signSession(userId);
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', token, {
httpOnly: true,
sameSite: 'lax',
path: '/',
maxAge: SESSION_MAX_AGE,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return response;
}

export async function DELETE() {
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', '', { httpOnly: true, maxAge: 0, path: '/' });
return response;
}
78 changes: 78 additions & 0 deletions frontend/src/app/pending/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
'use client';

import { useRouter } from 'next/navigation';
import Image from 'next/image';
import { useUser } from '@/context/UserContext';

export default function PendingPage() {
const router = useRouter();
const { signOut } = useUser();

async function handleSignOut() {
await signOut();
router.replace('/signin');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
color: 'var(--brand-text1, #e6edf3)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>
<h1 style={{
fontSize: '28px',
fontWeight: 600,
marginBottom: '12px',
textAlign: 'center',
letterSpacing: '-0.02em',
}}>
You&apos;re on the waitlist
</h1>
<p style={{
fontSize: '15px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
maxWidth: '340px',
lineHeight: 1.6,
marginBottom: '40px',
}}>
We&apos;ll reach out when your access is approved.
</p>
<button
onClick={handleSignOut}
style={{
background: 'transparent',
border: '1px solid rgba(255,255,255,0.15)',
color: 'var(--brand-text2, #8b949e)',
padding: '10px 24px',
borderRadius: '8px',
fontSize: '14px',
cursor: 'pointer',
transition: 'border-color 0.2s, color 0.2s',
}}
onMouseEnter={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.35)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text1, #e6edf3)';
}}
onMouseLeave={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.15)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text2, #8b949e)';
}}
>
Sign out
</button>
</div>
);
}
24 changes: 21 additions & 3 deletions frontend/src/app/signin/callback/page.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,18 +7,36 @@ import { useUser } from '@/context/UserContext';
function CallbackInner() {
const searchParams = useSearchParams();
const router = useRouter();
const { setActiveUser } = useUser();
const { setActiveUser, confirmApproved } = useUser();

useEffect(() => {
const userId = searchParams.get('user_id');
const name = searchParams.get('name');
const avatar = searchParams.get('avatar');
const isApproved = searchParams.get('is_approved') === 'true';
const error = searchParams.get('error');

if (error === 'not_approved' || !isApproved) {
router.replace('/pending');
return;
}

if (userId && name) {
setActiveUser(userId, name, avatar || '');
router.replace('/');
fetch('/api/auth/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId }),
}).then(res => {
if (res.ok) {
confirmApproved();
router.replace('/dashboard');
} else {
router.replace('/signin');
}
});
} else {
router.replace('/');
router.replace('/signin');
}
}, []); // eslint-disable-line react-hooks/exhaustive-deps

Expand Down
114 changes: 114 additions & 0 deletions frontend/src/app/signin/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
'use client';

import { Suspense } from 'react';
import { useSearchParams } from 'next/navigation';
import Image from 'next/image';

const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:5000';

function SignInInner() {
const searchParams = useSearchParams();
const error = searchParams.get('error');

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>

{error === 'not_approved' && (
<div style={{
marginBottom: '24px',
padding: '12px 20px',
borderRadius: '8px',
background: 'rgba(234, 179, 8, 0.12)',
border: '1px solid rgba(234, 179, 8, 0.3)',
color: '#ca8a04',
fontSize: '14px',
textAlign: 'center',
maxWidth: '360px',
}}>
Your account is pending approval.
</div>
)}

<div style={{
background: 'var(--bg-panel, #161b22)',
border: '1px solid rgba(255,255,255,0.08)',
borderRadius: '16px',
padding: '40px',
width: '100%',
maxWidth: '380px',
}}>
<h2 style={{
fontSize: '22px',
fontWeight: 600,
color: 'var(--brand-text1, #e6edf3)',
textAlign: 'center',
marginBottom: '8px',
letterSpacing: '-0.02em',
}}>
Welcome back
</h2>
<p style={{
fontSize: '14px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
marginBottom: '28px',
}}>
Sign in to continue
</p>

<button
onClick={() => { window.location.href = `${API_URL}/api/auth/google`; }}
style={{
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '12px',
padding: '12px 20px',
background: '#ffffff',
border: '1px solid #d1d5db',
borderRadius: '10px',
fontSize: '14px',
fontWeight: 500,
color: '#111827',
cursor: 'pointer',
transition: 'box-shadow 0.2s',
}}
onMouseEnter={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = '0 2px 8px rgba(0,0,0,0.12)'; }}
onMouseLeave={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = 'none'; }}
>
<svg width="18" height="18" viewBox="0 0 24 24">
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4" />
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853" />
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05" />
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335" />
</svg>
Continue with Google
</button>
</div>
</div>
);
}

export default function SignInPage() {
return (
<Suspense fallback={<div style={{ minHeight: '100vh', background: '#0d1117' }} />}>
<SignInInner />
</Suspense>
);
}
4 changes: 2 additions & 2 deletions frontend/src/components/Navbar.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,10 +89,10 @@ export default function Navbar() {
}
};

const handleSignOut = () => {
const handleSignOut = async () => {
setMenuOpen(false);
setMobileNavOpen(false);
signOut();
await signOut();
router.push('/');
};

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/db/migration_add_is_approved.sql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS is_approved BOOLEAN NOT NULL DEFAULT false;
11 changes: 6 additions & 5 deletions backend/db/supabase_schema.sql
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,11 +10,12 @@ CREATE TABLE IF NOT EXISTS users (
email TEXT,
streak_count INTEGER DEFAULT 0,
last_active_date TEXT,
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google'
room_id TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
google_id TEXT UNIQUE,
avatar_url TEXT,
auth_provider TEXT DEFAULT 'google',
is_approved BOOLEAN NOT NULL DEFAULT false
);

CREATE INDEX IF NOT EXISTS idx_users_google_id ON users(google_id);
Expand Down
20 changes: 18 additions & 2 deletions backend/routes/auth.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,6 +68,15 @@ def _generate_pkce_pair():
return code_verifier, code_challenge


@router.get("/me")
def get_me(user_id: str = Query(...)):
"""Return approval status for a given user_id (used by Next.js session API route)."""
user = table("users").select("id,is_approved", filters={"id": f"eq.{user_id}"})
if not user:
raise HTTPException(status_code=404, detail="User not found")
return {"user_id": user_id, "is_approved": bool(user[0]["is_approved"])}


@router.get("/google")
def google_login():
"""Redirect to Google consent screen with identity + calendar scopes."""
Expand DownExpand Up@@ -117,19 +126,21 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
)

# Determine user_id: check if this Google ID already exists
existing = table("users").select("id", filters={"google_id": f"eq.{google_id}"})
existing = table("users").select("id,is_approved", filters={"google_id": f"eq.{google_id}"})
if existing:
user_id = existing[0]["id"]
is_approved = existing[0]["is_approved"]
# Update name/avatar in case they changed
table("users").update(
{"name": name, "avatar_url": avatar_url, "email": email},
filters={"id": f"eq.{user_id}"},
)
else:
# Check if a user with this email exists (migration from old system)
email_match = table("users").select("id", filters={"email": f"eq.{email}"})
email_match = table("users").select("id,is_approved", filters={"email": f"eq.{email}"})
if email_match:
user_id = email_match[0]["id"]
is_approved = email_match[0]["is_approved"]
table("users").update(
{
"google_id": google_id,
Expand All@@ -142,6 +153,7 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
else:
# Create new user
user_id = f"user_{google_id}"
is_approved = False
table("users").insert({
"id": user_id,
"name": name,
Expand All@@ -162,10 +174,14 @@ def google_callback(code: str = Query(...), state: str = Query(None)):
on_conflict="user_id",
)

if not is_approved:
return RedirectResponse(f"{FRONTEND_URL}/pending")

# Redirect to frontend with user info
params = urlencode({
"user_id": user_id,
"name": name,
"avatar": avatar_url,
"is_approved": "true",
})
return RedirectResponse(f"{FRONTEND_URL}/signin/callback?{params}")
55 changes: 55 additions & 0 deletions frontend/src/app/api/auth/session/route.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
import { NextRequest, NextResponse } from 'next/server';
import { signSession, SESSION_MAX_AGE } from '@/lib/sessionToken';

const API_URL = process.env.NEXT_PUBLIC_API_URL;

export async function POST(request: NextRequest) {
if (!API_URL) {
return NextResponse.json({ error: 'NEXT_PUBLIC_API_URL not configured' }, { status: 500 });
}

const { userId } = await request.json();
if (!userId || typeof userId !== 'string') {
return NextResponse.json({ error: 'Missing userId' }, { status: 400 });
}

// Verify with the backend that the user exists and is approved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove the obvious inline comment to match repo style.

Line 12 explains directly-following code and is not non-obvious logic.

As per coding guidelines, "No docstrings or comments unless the logic is non-obvious".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@frontend/src/app/api/auth/session/route.ts` at line 12, Remove the inline
comment "// Verify with the backend that the user exists and is approved." from
the session route handler code (the comment directly above the backend
user/approval verification block) so the file no longer contains
obvious-following-code comments; leave the surrounding verification logic (the
handler/function that performs the backend user existence/approval check)
unchanged.

let approved = false;
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 3000);
let res: Response;
try {
res = await fetch(`${API_URL}/auth/me?user_id=${encodeURIComponent(userId)}`, { signal: controller.signal });
} finally {
clearTimeout(timeout);
}
if (!res.ok) {
return NextResponse.json({ error: 'User not found' }, { status: 401 });
}
const data = await res.json();
approved = data.is_approved === true;
} catch {
return NextResponse.json({ error: 'Backend unreachable' }, { status: 502 });
}

if (!approved) {
return NextResponse.json({ error: 'Not approved' }, { status: 403 });
}

const token = await signSession(userId);
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', token, {
httpOnly: true,
sameSite: 'lax',
path: '/',
maxAge: SESSION_MAX_AGE,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return response;
}

export async function DELETE() {
const response = NextResponse.json({ ok: true });
response.cookies.set('sapling_session', '', { httpOnly: true, maxAge: 0, path: '/' });
return response;
}
78 changes: 78 additions & 0 deletions frontend/src/app/pending/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
'use client';

import { useRouter } from 'next/navigation';
import Image from 'next/image';
import { useUser } from '@/context/UserContext';

export default function PendingPage() {
const router = useRouter();
const { signOut } = useUser();

async function handleSignOut() {
await signOut();
router.replace('/signin');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
color: 'var(--brand-text1, #e6edf3)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>
<h1 style={{
fontSize: '28px',
fontWeight: 600,
marginBottom: '12px',
textAlign: 'center',
letterSpacing: '-0.02em',
}}>
You&apos;re on the waitlist
</h1>
<p style={{
fontSize: '15px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
maxWidth: '340px',
lineHeight: 1.6,
marginBottom: '40px',
}}>
We&apos;ll reach out when your access is approved.
</p>
<button
onClick={handleSignOut}
style={{
background: 'transparent',
border: '1px solid rgba(255,255,255,0.15)',
color: 'var(--brand-text2, #8b949e)',
padding: '10px 24px',
borderRadius: '8px',
fontSize: '14px',
cursor: 'pointer',
transition: 'border-color 0.2s, color 0.2s',
}}
onMouseEnter={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.35)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text1, #e6edf3)';
}}
onMouseLeave={e => {
(e.currentTarget as HTMLButtonElement).style.borderColor = 'rgba(255,255,255,0.15)';
(e.currentTarget as HTMLButtonElement).style.color = 'var(--brand-text2, #8b949e)';
}}
>
Sign out
</button>
</div>
);
}
24 changes: 21 additions & 3 deletions frontend/src/app/signin/callback/page.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,18 +7,36 @@ import { useUser } from '@/context/UserContext';
function CallbackInner() {
const searchParams = useSearchParams();
const router = useRouter();
const { setActiveUser } = useUser();
const { setActiveUser, confirmApproved } = useUser();

useEffect(() => {
const userId = searchParams.get('user_id');
const name = searchParams.get('name');
const avatar = searchParams.get('avatar');
const isApproved = searchParams.get('is_approved') === 'true';
const error = searchParams.get('error');

if (error === 'not_approved' || !isApproved) {
router.replace('/pending');
return;
}

if (userId && name) {
setActiveUser(userId, name, avatar || '');
router.replace('/');
fetch('/api/auth/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId }),
}).then(res => {
if (res.ok) {
confirmApproved();
router.replace('/dashboard');
} else {
router.replace('/signin');
}
});
} else {
router.replace('/');
router.replace('/signin');
}
}, []); // eslint-disable-line react-hooks/exhaustive-deps

Expand Down
114 changes: 114 additions & 0 deletions frontend/src/app/signin/page.tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
'use client';

import { Suspense } from 'react';
import { useSearchParams } from 'next/navigation';
import Image from 'next/image';

const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:5000';

function SignInInner() {
const searchParams = useSearchParams();
const error = searchParams.get('error');

return (
<div style={{
minHeight: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-base, #0d1117)',
padding: '24px',
}}>
<Image
src="/sapling-word-icon.png"
alt="Sapling"
width={140}
height={40}
style={{ marginBottom: '40px', objectFit: 'contain' }}
/>

{error === 'not_approved' && (
<div style={{
marginBottom: '24px',
padding: '12px 20px',
borderRadius: '8px',
background: 'rgba(234, 179, 8, 0.12)',
border: '1px solid rgba(234, 179, 8, 0.3)',
color: '#ca8a04',
fontSize: '14px',
textAlign: 'center',
maxWidth: '360px',
}}>
Your account is pending approval.
</div>
)}

<div style={{
background: 'var(--bg-panel, #161b22)',
border: '1px solid rgba(255,255,255,0.08)',
borderRadius: '16px',
padding: '40px',
width: '100%',
maxWidth: '380px',
}}>
<h2 style={{
fontSize: '22px',
fontWeight: 600,
color: 'var(--brand-text1, #e6edf3)',
textAlign: 'center',
marginBottom: '8px',
letterSpacing: '-0.02em',
}}>
Welcome back
</h2>
<p style={{
fontSize: '14px',
color: 'var(--brand-text2, #8b949e)',
textAlign: 'center',
marginBottom: '28px',
}}>
Sign in to continue
</p>

<button
onClick={() => { window.location.href = `${API_URL}/api/auth/google`; }}
style={{
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '12px',
padding: '12px 20px',
background: '#ffffff',
border: '1px solid #d1d5db',
borderRadius: '10px',
fontSize: '14px',
fontWeight: 500,
color: '#111827',
cursor: 'pointer',
transition: 'box-shadow 0.2s',
}}
onMouseEnter={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = '0 2px 8px rgba(0,0,0,0.12)'; }}
onMouseLeave={e => { (e.currentTarget as HTMLButtonElement).style.boxShadow = 'none'; }}
>
<svg width="18" height="18" viewBox="0 0 24 24">
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4" />
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853" />
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05" />
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335" />
</svg>
Continue with Google
</button>
</div>
</div>
);
}

export default function SignInPage() {
return (
<Suspense fallback={<div style={{ minHeight: '100vh', background: '#0d1117' }} />}>
<SignInInner />
</Suspense>
);
}
4 changes: 2 additions & 2 deletions frontend/src/components/Navbar.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,10 +89,10 @@ export default function Navbar() {
}
};

const handleSignOut = () => {
const handleSignOut = async () => {
setMenuOpen(false);
setMobileNavOpen(false);
signOut();
await signOut();
router.push('/');
};

Expand Down
Loading
Loading