Skip to content
Open
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
Binary file added docs/screenshots/issue-35-mobile-onboarding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 23 additions & 6 deletions frontend/src/lib/supabase.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,52 @@
import { createClient } from '@supabase/supabase-js';
import { createClient, SupabaseClient } from '@supabase/supabase-js';

const supabaseUrl = import.meta.env.VITE_SUPABASE_URL!;
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY!;
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL ?? '';
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY ?? '';

export const supabase = createClient(supabaseUrl, supabaseAnonKey);
export const supabase: SupabaseClient =
supabaseUrl && supabaseAnonKey
? createClient(supabaseUrl, supabaseAnonKey)
: (null as unknown as SupabaseClient);
Comment on lines +6 to +9
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

supabase is exported as SupabaseClient but can be null at runtime via (null as unknown as SupabaseClient). This defeats strict null-safety and can lead to runtime crashes in code that uses supabase directly (e.g., frontend/src/lib/api.ts calls supabase.auth.getSession() without a guard). Prefer exporting supabase as SupabaseClient | null (or undefined) and updating call sites/helpers to handle the unconfigured case explicitly (or provide a safe stub implementation).

Suggested change
export const supabase: SupabaseClient =
supabaseUrl && supabaseAnonKey
? createClient(supabaseUrl, supabaseAnonKey)
: (null as unknown as SupabaseClient);
export const supabase: SupabaseClient | null =
supabaseUrl && supabaseAnonKey
? createClient(supabaseUrl, supabaseAnonKey)
: null;

Copilot uses AI. Check for mistakes.

// Helper to get current session
export async function getSession() {
const { data: { session } } = await supabase.auth.getSession();
return session;
if (!supabase) return null;
try {
const { data: { session } } = await supabase.auth.getSession();
return session;
} catch {
return null;
}
}

// Helper to get current user
export async function getCurrentUser() {
if (!supabase) return null;
const { data: { user } } = await supabase.auth.getUser();
return user;
}

// Helper to sign in anonymously
export async function signInAnonymously() {
if (!supabase) {
return { data: null, error: { message: 'Supabase not configured. Add VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY to .env' } as any };
}
Comment on lines +31 to +33
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

When Supabase isn’t configured, signInAnonymously returns { data: null, error: { message } } with as any. This forces consumers to rely on runtime checks and any, and makes it easy to accidentally dereference data assuming the normal Supabase response shape. Consider returning a typed object matching Supabase’s auth response shape (e.g., data: { user: null, session: null }) and a properly typed AuthError/Error, or throw a dedicated configuration error that callers can catch and surface.

Copilot uses AI. Check for mistakes.
const { data, error } = await supabase.auth.signInAnonymously();
return { data, error };
}

// Helper to sign out
export async function signOut() {
if (!supabase) return { error: null };
const { error } = await supabase.auth.signOut();
return { error };
}

// Helper to create user profile
export async function createProfile(userId: string, nickname: string, avatar: string) {
if (!supabase) {
return { data: null, error: { message: 'Supabase not configured' } as any };
}
const { data, error } = await supabase
.from('profiles')
.insert({
Expand All @@ -46,6 +62,7 @@ export async function createProfile(userId: string, nickname: string, avatar: st

// Helper to get user profile
export async function getProfile(userId: string) {
if (!supabase) return { data: null, error: { message: 'Supabase not configured' } as any };
const { data, error } = await supabase
.from('profiles')
.select('*')
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ export default function Home() {
}, []);

async function checkSession() {
const session = await getSession();
if (session) {
navigate('/dashboard');
} else {
try {
const session = await getSession();
if (session) {
navigate('/dashboard');
}
} catch {
// ignore
} finally {
setLoading(false);
}
Comment on lines +14 to 23
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

getSession already handles the unconfigured Supabase case and catches errors internally (returns null). The extra try/catch { /* ignore */ } here is redundant and can hide unexpected errors during local debugging. Consider removing the try/catch and relying on getSession’s behavior (or at least logging the caught error in development).

Suggested change
try {
const session = await getSession();
if (session) {
navigate('/dashboard');
}
} catch {
// ignore
} finally {
setLoading(false);
}
const session = await getSession();
if (session) {
navigate('/dashboard');
}
setLoading(false);

Copilot uses AI. Check for mistakes.
}
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/pages/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export default function Onboarding() {
}

return (
<div className="min-h-screen bg-gradient-to-b from-blue-50 to-white flex items-center justify-center px-4">
<div className="max-w-md w-full">
<div className="min-h-screen bg-gradient-to-b from-blue-50 to-white flex items-center justify-center px-4 py-6 overflow-x-hidden">
<div className="max-w-md w-full min-w-0">
{/* Crisis Banner */}
<div className="bg-red-600 text-white py-2 px-4 rounded-lg text-center text-sm mb-6">
<strong>⚠️ IN CRISIS?</strong> 🇺🇸 988 | 🇮🇳 9152987821 (iCall) | KIRAN 1800-599-0019
Expand Down Expand Up @@ -90,21 +90,21 @@ export default function Onboarding() {
<p className="text-xs text-gray-500 mt-1">3-20 characters, no personal info</p>
</div>

{/* Avatar Selection */}
<div className="mb-6">
{/* Avatar Selection - responsive for mobile */}
<div className="mb-6 min-w-0">
<label className="block text-sm font-medium text-gray-700 mb-2">
Choose an Avatar
</label>
<div className="grid grid-cols-5 gap-2">
<div className="grid grid-cols-4 sm:grid-cols-5 gap-2 sm:gap-2">
{AVATAR_OPTIONS.map((avatar) => (
<button
key={avatar}
type="button"
onClick={() => setSelectedAvatar(avatar)}
className={`text-4xl p-3 rounded-lg border-2 transition-all ${
className={`min-h-[48px] min-w-[48px] sm:min-h-[52px] sm:min-w-[52px] flex items-center justify-center text-2xl sm:text-3xl md:text-4xl p-2 sm:p-3 rounded-lg border-2 transition-all touch-manipulation ${
selectedAvatar === avatar
? 'border-primary-600 bg-primary-50 scale-110'
: 'border-gray-300 hover:border-primary-400'
? 'border-primary-600 bg-primary-50 scale-105 sm:scale-110'
: 'border-gray-300 hover:border-primary-400 active:border-primary-400'
}`}
disabled={loading}
>
Expand Down
Loading