-
-
Notifications
You must be signed in to change notification settings - Fork 6
Finalize and Optimize Supabase Integration #505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1747a21
d884663
2739a8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| // File: components/settings/components/user-management-form.tsx | ||
| import React, { useState } from 'react'; | ||
| import { UseFormReturn, useFieldArray } from 'react-hook-form'; | ||
| import { Button } from '@/components/ui/button'; | ||
|
|
@@ -9,7 +8,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@ | |
| import { FormField, FormItem, FormLabel, FormControl, FormMessage } from "@/components/ui/form"; | ||
| import { Trash2, Edit3, UserPlus, Loader2 } from 'lucide-react'; | ||
| import { useToast } from '@/components/ui/hooks/use-toast'; | ||
| import { addUser } from '@/lib/actions/users'; | ||
| import { addUser, type UserRole } from '@/lib/actions/users'; | ||
| import type { SettingsFormValues } from './settings'; | ||
|
|
||
| interface UserManagementFormProps { | ||
|
|
@@ -24,15 +23,11 @@ export function UserManagementForm({ form }: UserManagementFormProps) { | |
| const { toast } = useToast(); | ||
| const [isAddingUser, setIsAddingUser] = useState(false); | ||
|
|
||
| // const watchNewUserEmail = form.watch("newUserEmail", ""); // Not strictly needed for logic below | ||
| // const watchNewUserRole = form.watch("newUserRole", "viewer"); // Not strictly needed for logic below | ||
|
|
||
| const handleAddUser = async () => { | ||
| setIsAddingUser(true); | ||
| const newUserEmail = form.getValues("newUserEmail"); | ||
| const newUserRole = form.getValues("newUserRole") || "viewer"; // Ensure role has a default | ||
| const newUserRole = form.getValues("newUserRole") || "viewer"; | ||
|
|
||
| // Client-side validation first | ||
| if (!newUserEmail) { | ||
| form.setError("newUserEmail", { type: "manual", message: "Email is required." }); | ||
| setIsAddingUser(false); | ||
|
|
@@ -43,27 +38,29 @@ export function UserManagementForm({ form }: UserManagementFormProps) { | |
| setIsAddingUser(false); | ||
| return; | ||
| } | ||
| // Client-side check if user already exists in the local list | ||
| if (fields.some(user => user.email === newUserEmail)) { | ||
| form.setError("newUserEmail", { type: "manual", message: "User with this email already exists locally." }); | ||
| setIsAddingUser(false); | ||
| return; | ||
| } | ||
| // Clear any previous local errors for newUserEmail if client checks pass | ||
| form.clearErrors("newUserEmail"); | ||
|
|
||
| try { | ||
| const result = await addUser('default-user', { email: newUserEmail, role: newUserRole }); | ||
| const result = await addUser({ email: newUserEmail, role: newUserRole as UserRole }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
echo "=== Checking lib/actions/users.ts for addUser implementation ==="
fd -n "users.ts" -path "*/lib/actions/*" | head -1 | xargs cat -n | sed -n '40,65p'
echo ""
echo "=== Searching for schema files to find constraints ==="
fd -e sql | head -20
echo ""
echo "=== Checking for unique constraint on users.email in schema ==="
fd -e sql -o -e ts -o -e js | xargs grep -n "email.*unique\|unique.*email" 2>/dev/null | head -20Repository: QueueLab/QCX Length of output: 700 🏁 Script executed: #!/bin/bash
echo "=== Find lib/actions/users.ts ==="
git ls-files | grep "lib/actions/users.ts"
echo ""
echo "=== Read lib/actions/users.ts (full file to understand addUser) ==="
git ls-files | grep "lib/actions/users.ts" | xargs wc -l
echo ""
echo "=== Read drizzle migration files to check schema ==="
git ls-files | grep "drizzle/migrations" | head -2 | xargs wc -lRepository: QueueLab/QCX Length of output: 373 🏁 Script executed: #!/bin/bash
echo "=== Find and read lib/actions/users.ts ==="
git ls-files | grep "lib/actions/users.ts" | xargs cat -n
echo ""
echo "=== Check migration 0000 for schema ==="
cat drizzle/migrations/0000_sweet_metal_master.sql
echo ""
echo "=== Check migration 0001 for changes ==="
cat drizzle/migrations/0001_add_calendar_notes.sqlRepository: QueueLab/QCX Length of output: 9144 🏁 Script executed: #!/bin/bash
echo "=== Find and read database schema definition ==="
git ls-files | grep -E "lib/db/schema" | xargs cat -n
echo ""
echo "=== Search for RLS policies on users table ==="
rg "users.*POLICY|CREATE POLICY.*users" --type=sql
echo ""
echo "=== Search for triggers related to auth sync ==="
rg "trigger|CREATE.*FUNCTION" --type=sql -i
echo ""
echo "=== Check for any Supabase client admin methods ==="
rg "createUser|inviteUserByEmail|auth.*admin" --type=ts --type=jsRepository: QueueLab/QCX Length of output: 8316 🏁 Script executed: #!/bin/bash
echo "=== Search for auth callbacks, signup, or user sync flows ==="
rg "auth.*callback|onAuthStateChanged|session.*user|auth.*user.*create" --type=ts --type=js -i
echo ""
echo "=== Check for middleware or hooks handling auth state ==="
git ls-files | grep -E "middleware|auth.*hook|callback" | head -20
echo ""
echo "=== Search for any existing unique constraints in schema ==="
rg "unique()" --type=ts | head -20Repository: QueueLab/QCX Length of output: 554 🏁 Script executed: #!/bin/bash
echo "=== Read middleware.ts to understand auth flow ==="
cat -n middleware.ts
echo ""
echo "=== Check lib/auth/get-current-user.ts ==="
cat -n lib/auth/get-current-user.ts
echo ""
echo "=== Search for signup or user creation entry points ==="
rg "signup|register|createUser|newUser" --type=ts --type=tsx -i | head -30Repository: QueueLab/QCX Length of output: 6827 🏁 Script executed: #!/bin/bash
echo "=== Search for signup/register endpoints ==="
fd -e ts -e tsx -e js -e jsx | xargs grep -l "signup\|register\|auth.*route\|/api/auth" 2>/dev/null | head -20
echo ""
echo "=== Check for any API routes related to auth ==="
find . -path "*/api/auth*" -o -path "*/api/*auth*" 2>/dev/null | head -20
echo ""
echo "=== Verify: does addUser expect auth.users to already exist? ==="
rg "email.*already.*exist|duplicate.*email|constraint" lib/actions/users.tsRepository: QueueLab/QCX Length of output: 253 🏁 Script executed: #!/bin/bash
echo "=== Check lib/supabase/client.ts ==="
cat -n lib/supabase/client.ts
echo ""
echo "=== Look for any documentation or comments about user management ==="
rg "admin.*user|invite.*user|sync.*auth" --type=ts -i | head -20
echo ""
echo "=== Check where addUser is actually called from ==="
rg "addUser" --type=ts --type=tsxRepository: QueueLab/QCX Length of output: 2638 🏁 Script executed: #!/bin/bash
echo "=== Find where addUser is called ==="
rg "addUser" --type=ts | grep -v "export async function addUser"
echo ""
echo "=== Check user-management-form.tsx to see the context ==="
find . -name "user-management-form.tsx" | xargs cat -n | head -100Repository: QueueLab/QCX Length of output: 5244
The Consider either:
🤖 Prompt for AI Agents |
||
|
|
||
| if (result.error) { | ||
| toast({ title: 'Error adding user', description: result.error, variant: 'destructive' }); | ||
| form.setError("newUserEmail", { type: "manual", message: result.error }); // Show server error on field | ||
| form.setError("newUserEmail", { type: "manual", message: result.error }); | ||
| } else if (result.user) { | ||
| toast({ title: 'User Added', description: `${result.user.email} was successfully added.` }); | ||
| append(result.user); // Add user with ID from server | ||
| append({ | ||
| id: result.user.id, | ||
| email: result.user.email || '', | ||
| role: result.user.role || 'viewer' | ||
| }); | ||
| form.resetField("newUserEmail"); | ||
| form.resetField("newUserRole"); // Or set to default: form.setValue("newUserRole", "viewer"); | ||
| form.clearErrors("newUserEmail"); // Clear any previous errors | ||
| form.resetField("newUserRole"); | ||
| form.clearErrors("newUserEmail"); | ||
| } | ||
| } catch (error) { | ||
| console.error("Failed to add user:", error); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
useRouteris imported and instantiated but never used.routerwas previously used forrouter.refresh(), which has been removed. The import and declaration are now dead code.Proposed fix
-import { useRouter } from 'next/navigation'- const router = useRouter()Also applies to: 67-67
🤖 Prompt for AI Agents