This document explains how to set up and use Supabase with the Lik app for authentication, real-time features, and CRUD operations.
- Go to supabase.com and create a new account
- Create a new project
- Wait for the project to be fully initialized
- Go to the SQL Editor in your Supabase dashboard
- Copy the contents of
supabase-schema.sqland run it - This will create all the necessary tables, indexes, RLS policies, and triggers
- In your Supabase dashboard, go to Authentication > Settings
- Enable the authentication providers you want to use:
- Email/Password (enabled by default)
- Google OAuth
- GitHub OAuth
- Discord OAuth
- For OAuth providers, you'll need to configure them with your app's credentials
- Copy
.env.exampleto.env - Fill in your Supabase project details:
VITE_SUPABASE_URL=https://your-project-id.supabase.co VITE_SUPABASE_ANON_KEY=your-anon-key
If you want to handle file uploads (profile pictures, post images, etc.):
- Go to Storage in your Supabase dashboard
- Create buckets for different file types:
avatars- for profile picturesposts- for post mediarestaurants- for restaurant images
- Set up RLS policies for each bucket as needed
- Email/password authentication
- OAuth providers (Google, GitHub, Discord)
- Automatic profile creation on signup
- Session management
- Protected routes
- Live message updates
- Real-time notifications
- Live post updates (likes, comments)
- Follow/unfollow updates
- Posts: Create, read, update, delete posts with media
- Comments: Threaded comments with likes
- Likes: Like/unlike posts and comments
- Follows: Follow/unfollow users
- Messages: Direct messaging and group chats
- Bounties & Quests: Gamification features
- Events: Food events management
- Notifications: System notifications
The database includes the following main tables:
profiles- User profiles with gamification statsrestaurants- Restaurant informationdishes- Menu items and dishesposts- User posts and reviewsbounties- Restaurant challengesquests- Multi-location challengesevents- Food eventsmessages- Chat messageschats- Chat roomscomments- Post commentslikes- Post and comment likesfollows- User relationshipsnotifications- System notifications
import { usePosts } from '@/hooks/useSupabase'
const { createPost } = usePosts()
const handleCreatePost = async () => {
await createPost({
user_id: user.id,
content: "Amazing pasta!",
restaurant_id: "restaurant-uuid",
rating: 9.5,
media_urls: ["image-url"],
tags: ["italian", "pasta"]
})
}import { useRealtimeSubscription } from '@/hooks/useSupabase'
// Listen for new messages in a chat
useRealtimeSubscription(
'messages',
(payload) => {
if (payload.eventType === 'INSERT') {
setMessages(prev => [...prev, payload.new])
}
},
`chat_id=eq.${chatId}`
)import { useAuth } from '@/contexts/AuthContext'
const { user, signIn, signOut, updateProfile } = useAuth()
// Sign in
await signIn('email@example.com', 'password')
// Update profile
await updateProfile({
display_name: 'New Name',
bio: 'Food enthusiast'
})All tables have RLS enabled with appropriate policies:
- Users can only access their own private data
- Public data (posts, restaurants) is readable by everyone
- Users can only modify their own content
Real-time subscriptions respect RLS policies, ensuring users only receive updates for data they have access to.
Storage buckets can be configured with RLS policies to control who can upload/access files.
Make sure to set the correct environment variables in production:
VITE_SUPABASE_URLVITE_SUPABASE_ANON_KEY
Update OAuth provider settings with your production URLs.
Set up regular database backups through the Supabase dashboard.
Use Supabase's built-in monitoring to track:
- API usage
- Database performance
- Real-time connections
- Storage usage
- RLS Policy Errors: Make sure your policies allow the operations you're trying to perform
- Real-time Not Working: Check that the table is added to the realtime publication
- Authentication Issues: Verify your environment variables and OAuth configurations
- File Upload Failures: Check storage bucket policies and file size limits
Enable Supabase logging in development:
import { supabase } from '@/lib/supabase'
// Enable debug mode
supabase.auth.onAuthStateChange((event, session) => {
console.log('Auth event:', event, session)
})The schema includes optimized indexes for:
- Post queries by user/restaurant
- Message queries by chat
- Notification queries by user
- Follow relationships
- Only subscribe to channels you need
- Unsubscribe when components unmount
- Use filters to reduce unnecessary updates
- Use
select()to only fetch needed columns - Implement pagination for large datasets
- Use appropriate filters and ordering
- Analytics: Add analytics tracking for user behavior
- Push Notifications: Implement push notifications for mobile
- Advanced Search: Add full-text search capabilities
- Caching: Implement client-side caching for better performance
- Offline Support: Add offline-first capabilities with sync