Loading repository data…
Loading repository data…
Kanishk1420 / repository
A production-ready Supabase backend for a personal notes service with custom Edge Functions. This service provides a secure and scalable way to create and manage personal notes with features like tag filtering, pagination, and robust security.
A production-ready Supabase backend for a personal notes service with custom Edge Functions. This service provides a secure and scalable way to create and manage personal notes with features like tag filtering, pagination, and robust security.
This project implements a custom notes service using Supabase with the following components:
schema.sql fileindex.ts fileget_notes.ts into the editorpost_notes.ts# Install Node.js if not already installed
# Install Supabase CLI
npm install -g supabase
# Create a new directory
mkdir notes-service
cd notes-service
# Initialize Supabase project
supabase init
# Login to Supabase
supabase login
# Link to your existing project
supabase link --project-ref your-project-ref
# Create schema.sql file with the provided schema
# Then apply it to your project
supabase db push
mkdir -p supabase/functions/get_notes
mkdir -p supabase/functions/post_notes
supabase/functions/get_notes/index.ts with the content of get_notes.tssupabase/functions/post_notes/index.ts with the content of post_notes.tssupabase functions deploy get_notes
supabase functions deploy post_notes
Using curl (replace placeholders with your actual values):
curl -X POST https://your-project-ref.functions.supabase.co/post_notes \
-H "Authorization: Bearer your-jwt-token" \
-H "Content-Type: application/json" \
-d '{
"title": "My First Note",
"content": "This is a test note from Supabase Edge Function",
"user_id": "the-user-uuid",
"tags": ["test", "api"]
}'
Expected response:
{
"message": "Note created successfully",
"data": {
"id": "generated-uuid",
"user_id": "the-user-uuid",
"title": "My First Note",
"content": "This is a test note from Supabase Edge Function",
"created_at": "2025-04-26T18:00:00.000Z",
"updated_at": "2025-04-26T18:00:00.000Z",
"tags": ["test", "api"]
}
}
Basic retrieval:
curl -X GET "https://your-project-ref.functions.supabase.co/get_notes?user_id=the-user-uuid" \
-H "Authorization: Bearer your-jwt-token"
With filtering and pagination:
curl -X GET "https://your-project-ref.functions.supabase.co/get_notes?user_id=the-user-uuid&tag=test&limit=5&offset=0&orderBy=created_at&order=desc" \
-H "Authorization: Bearer your-jwt-token"
Expected response:
{
"message": "Notes retrieved successfully",
"data": [
{
"id": "note-uuid",
"user_id": "the-user-uuid",
"title": "My First Note",
"content": "This is a test note from Supabase Edge Function",
"created_at": "2025-04-26T18:00:00.000Z",
"updated_at": "2025-04-26T18:00:00.000Z",
"tags": ["test", "api"]
}
],
"pagination": {
"offset": 0,
"limit": 5,
"total": 1
}
}
Retrieves notes for a specific user with optional filtering and pagination.
Parameters:
user_id (required): The UUID of the user whose notes to retrievetag (optional): Filter notes by specified taglimit (optional): Maximum number of notes to return (default: 100)offset (optional): Number of notes to skip (default: 0)orderBy (optional): Field to order by (default: created_at)order (optional): Order direction, 'asc' or 'desc' (default: desc)Response: JSON object containing notes and pagination information
Creates a new note for a specific user.
Request Body:
{
"user_id": "user-uuid",
"title": "Note Title",
"content": "Note content goes here",
"tags": ["tag1", "tag2"] // Optional
}
Response: JSON object containing the created note
The database schema is designed with the following considerations:
auth.users with CASCADE delete to maintain referential integrity.created_at and updated_at fields with defaults to track note history.user_id to optimize query performance when fetching notes.updated_at timestamp.This service implements several security measures:
Authentication Errors:
Function Deployment Issues:
Database Schema Issues:
CORS Issues: