* refactor: consolidate AGENTS.md and CLAUDE.md files, update tech stack and architecture details - Merged content from CLAUDE.md into AGENTS.md for better organization. - Updated tech stack section to reflect the current technologies used, including Next.js, Supabase, and Tailwind CSS. - Enhanced monorepo structure documentation with detailed directory purposes. - Streamlined multi-tenant architecture explanation and essential commands. - Added key patterns for naming conventions and server actions. - Removed outdated agent files related to Playwright and PostgreSQL, ensuring a cleaner codebase. - Bumped version to 2.23.7 to reflect changes.
75 lines
1.7 KiB
Markdown
75 lines
1.7 KiB
Markdown
# Database & Authentication
|
|
|
|
## Skills
|
|
|
|
For database work:
|
|
- `/postgres-expert` - Schemas, RLS, migrations
|
|
|
|
## Client Usage
|
|
|
|
### Server Components (Preferred)
|
|
|
|
```typescript
|
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
|
|
|
const client = getSupabaseServerClient();
|
|
const { data } = await client.from('table').select('*');
|
|
// RLS automatically enforced
|
|
```
|
|
|
|
### Client Components
|
|
|
|
```typescript
|
|
'use client';
|
|
import { useSupabase } from '@kit/supabase/hooks/use-supabase';
|
|
|
|
const supabase = useSupabase();
|
|
```
|
|
|
|
### Admin Client (Use Sparingly)
|
|
|
|
```typescript
|
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
|
|
|
// CRITICAL: Bypasses RLS - validate manually!
|
|
const adminClient = getSupabaseServerAdminClient();
|
|
```
|
|
|
|
## Existing Helper Functions
|
|
|
|
```sql
|
|
public.has_role_on_account(account_id, role?)
|
|
public.has_permission(user_id, account_id, permission)
|
|
public.is_account_owner(account_id)
|
|
public.has_active_subscription(account_id)
|
|
public.is_team_member(account_id, user_id)
|
|
public.is_super_admin()
|
|
```
|
|
|
|
## Type Generation
|
|
|
|
```typescript
|
|
import { Tables } from '@kit/supabase/database';
|
|
|
|
type Account = Tables<'accounts'>;
|
|
```
|
|
|
|
Never modify `database.types.ts` - regenerate with `pnpm supabase:web:typegen`.
|
|
|
|
## Authentication
|
|
|
|
```typescript
|
|
import { requireUser } from '@kit/supabase/require-user';
|
|
import { checkRequiresMultiFactorAuthentication } from '@kit/supabase/check-requires-mfa';
|
|
|
|
const user = await requireUser(client);
|
|
const requiresMfa = await checkRequiresMultiFactorAuthentication(client);
|
|
```
|
|
|
|
## Security Guidelines
|
|
|
|
- Standard client: Trust RLS
|
|
- Admin client: Validate everything manually
|
|
- Always add indexes for foreign keys
|
|
- Storage paths must include account_id
|