π Supabase Edge Functions for ttbkk ecosystem - API gateway with authentication, geocoding, and data management
ttbkk-edge is a collection of Supabase Edge Functions that serve as an API gateway for the ttbkk (λ‘λ³Άμ΄λ§΅) ecosystem. It provides:
- Geocoding API: Convert place names to coordinates using Kakao Maps API
- Authentication: Secure API access and user management
- Data Management: CRUD operations with proper authorization
- Rate Limiting: API usage control and monitoring
ttbkk-web (Frontend) β ttbkk-edge (API Gateway) β External APIs + Supabase
- Security: Hide API keys and manage authentication
- Consistency: Unified API interface for all clients
- Scalability: Edge-based serverless architecture
- Monitoring: Request logging and analytics
- Deno installed
- Supabase CLI installed
- Supabase project set up
- Kakao Maps API key
-
Clone and setup
git clone <repository-url> cd ttbkk-edge
-
Install Supabase CLI
npm install -g supabase
-
Link to your Supabase project
supabase link --project-ref your-project-id
-
Set environment variables
cp env.example .env # Edit .env with your actual values -
Start local development
supabase start npm run dev
-
Test the functions
curl -X POST http://localhost:54321/functions/v1/geocoding \ -H "Content-Type: application/json" \ -d '{"query": "κ°λ¨μ"}'
ttbkk-edge uses Supabase Auth with Google OAuth integration for user authentication.
Use Supabase client-side authentication:
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(
'https://izhutepzzveasglrlbcx.supabase.co',
'your-anon-key'
)
// Sign in with Google
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: 'http://localhost:3000/auth/callback'
}
})Endpoint: GET/PUT /functions/v1/user-profile
Headers:
Authorization: Bearer <user-jwt-token>
Content-Type: application/json
GET Response:
{
"success": true,
"data": {
"id": "user-uuid",
"display_name": "John Doe",
"avatar_url": "https://...",
"bio": "Love tteokbokki!",
"created_at": "2025-01-01T00:00:00Z",
"updated_at": "2025-01-01T00:00:00Z"
}
}PUT Request:
{
"display_name": "Jane Doe",
"avatar_url": "https://new-avatar-url.com",
"bio": "Tteokbokki enthusiast πΆοΈ"
}Endpoint: POST /functions/v1/geocoding
Request:
{
"query": "κ°λ¨μ",
"provider": "kakao",
"limit": 1
}Response:
{
"success": true,
"data": {
"latitude": 37.497952,
"longitude": 127.027619,
"address": "μμΈ κ°λ¨κ΅¬ μμΌλ",
"formatted_address": "κ°λ¨μ",
"provider": "kakao",
"confidence": 1.0
}
}Error Response:
{
"success": false,
"error": {
"code": "NOT_FOUND",
"message": "No results found for the given query"
}
}| Variable | Description | Required |
|---|---|---|
SUPABASE_URL |
Your Supabase project URL | β |
SUPABASE_ANON_KEY |
Supabase anonymous key | β |
SUPABASE_SERVICE_ROLE_KEY |
Supabase service role key | β |
KAKAO_API_KEY |
Kakao Maps API key | β |
GOOGLE_OAUTH_CLIENT_ID |
Google OAuth 2.0 Client ID | β |
GOOGLE_OAUTH_CLIENT_SECRET |
Google OAuth 2.0 Client Secret | β |
| Secret | Description |
|---|---|
SUPABASE_PROJECT_ID |
Your Supabase project reference ID |
SUPABASE_ACCESS_TOKEN |
Supabase access token for CLI |
KAKAO_API_KEY |
Kakao Maps API key |
- Push to
mainbranch - GitHub Actions automatically deploys to Supabase
# Deploy all functions
supabase functions deploy
# Deploy specific function
supabase functions deploy geocoding- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google+ API
- Go to APIs & Services > Credentials
- Click Create Credentials > OAuth 2.0 Client IDs
- Configure consent screen if needed
- Set Application type to Web application
- Add authorized redirect URIs:
https://izhutepzzveasglrlbcx.supabase.co/auth/v1/callbackhttp://localhost:54321/auth/v1/callback(for local development)
- Go to your Supabase project dashboard
- Navigate to Authentication > Providers
- Enable Google provider
- Enter your Google OAuth credentials:
- Client ID: From Google Cloud Console
- Client Secret: From Google Cloud Console
# In production (Supabase Dashboard > Settings > Edge Functions)
GOOGLE_OAUTH_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_OAUTH_CLIENT_SECRET=your-client-secret
# Or using Supabase CLI
supabase secrets set GOOGLE_OAUTH_CLIENT_ID=your-client-id
supabase secrets set GOOGLE_OAUTH_CLIENT_SECRET=your-client-secret# Start local Supabase
supabase start
# Test geocoding
curl -X POST http://localhost:54321/functions/v1/geocoding \
-H "Content-Type: application/json" \
-d '{"query": "νλμ
ꡬμ"}'curl -X POST https://your-project-id.supabase.co/functions/v1/geocoding \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-anon-key" \
-d '{"query": "κ°λ¨μ"}'- Function logs:
Supabase Dashboard > Edge Functions > Logs - Performance metrics:
Supabase Dashboard > Settings > API
All functions return standardized error responses:
400: Bad Request (invalid input)401: Unauthorized404: Not Found429: Rate Limited500: Internal Server Error
The geocoding function is designed to work with the ttbkk-mcp-server:
// MCP tool integration example
const geocodeResult = await fetch(`${TTBKK_EDGE_URL}/functions/v1/geocoding`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: 'κ°λ¨μ' })
})Frontend integration with proper error handling:
import { GeocodeResponse } from '@/types/geocoding'
export async function geocodeAddress(query: string): Promise<GeocodeResponse> {
const response = await fetch('/api/geocode', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query })
})
return response.json()
}- Use TypeScript for type safety
- Follow Deno conventions
- Implement proper error handling
- Include comprehensive logging
- Edge functions are optimized for low latency
- Implement caching where appropriate
- Monitor function execution time
- Validate all inputs
- Sanitize user queries
- Implement rate limiting
- Use proper CORS headers
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details.
- ttbkk-web - Frontend application
- ttbkk-mcp-server - MCP server for AI tools
- ttbkk-data - Data management tools