Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions lib/supabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import { createClient, SupabaseClient } from "@supabase/supabase-js";

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || "";
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || "";

// Browser-side client (anon key, respects RLS)
export const supabase: SupabaseClient<Database> | null =
supabaseUrl && supabaseAnonKey
? createClient<Database>(supabaseUrl, supabaseAnonKey)
: null;

// Server-side client (service role, bypasses RLS)
export function createServerClient(): SupabaseClient<Database> | null {
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY || "";
if (!supabaseUrl || !serviceRoleKey) return null;

return createClient<Database>(supabaseUrl, serviceRoleKey, {
auth: {
autoRefreshToken: false,
persistSession: false,
},
});
}

// ---------------------------------------------------------------------------
// Database types
// ---------------------------------------------------------------------------

export type Json =
| string
| number
| boolean
| null
| { [key: string]: Json | undefined }
| Json[];

export interface Database {
public: {
Tables: {
storylines: {
Row: {
id: number;
storyline_id: number;
writer_address: string;
token_address: string;
title: string;
plot_count: number;
last_plot_time: string | null;
has_deadline: boolean;
sunset: boolean;
writer_type: number | null;
hidden: boolean;
tx_hash: string;
log_index: number;
block_timestamp: string | null;
indexed_at: string;
};
Insert: {
id?: never;
storyline_id: number;
writer_address: string;
token_address: string;
title: string;
plot_count?: number;
last_plot_time?: string | null;
has_deadline?: boolean;
sunset?: boolean;
writer_type?: number | null;
hidden?: boolean;
tx_hash: string;
log_index: number;
block_timestamp?: string | null;
indexed_at?: string;
};
Update: {
id?: never;
storyline_id?: number;
writer_address?: string;
token_address?: string;
title?: string;
plot_count?: number;
last_plot_time?: string | null;
has_deadline?: boolean;
sunset?: boolean;
writer_type?: number | null;
hidden?: boolean;
tx_hash?: string;
log_index?: number;
block_timestamp?: string | null;
indexed_at?: string;
};
};
plots: {
Row: {
id: number;
storyline_id: number;
plot_index: number;
writer_address: string;
content_cid: string;
content_hash: string;
hidden: boolean;
tx_hash: string;
log_index: number;
block_timestamp: string | null;
indexed_at: string;
};
Insert: {
id?: never;
storyline_id: number;
plot_index: number;
writer_address: string;
content_cid: string;
content_hash: string;
hidden?: boolean;
tx_hash: string;
log_index: number;
block_timestamp?: string | null;
indexed_at?: string;
};
Update: {
id?: never;
storyline_id?: number;
plot_index?: number;
writer_address?: string;
content_cid?: string;
content_hash?: string;
hidden?: boolean;
tx_hash?: string;
log_index?: number;
block_timestamp?: string | null;
indexed_at?: string;
};
};
donations: {
Row: {
id: number;
storyline_id: number;
donor_address: string;
amount: string;
tx_hash: string;
log_index: number;
block_timestamp: string | null;
indexed_at: string;
};
Insert: {
id?: never;
storyline_id: number;
donor_address: string;
amount: string;
tx_hash: string;
log_index: number;
block_timestamp?: string | null;
indexed_at?: string;
};
Update: {
id?: never;
storyline_id?: number;
donor_address?: string;
amount?: string;
tx_hash?: string;
log_index?: number;
block_timestamp?: string | null;
indexed_at?: string;
};
};
};
};
}

// Convenience type aliases
export type Storyline = Database["public"]["Tables"]["storylines"]["Row"];
export type Plot = Database["public"]["Tables"]["plots"]["Row"];
export type Donation = Database["public"]["Tables"]["donations"]["Row"];
128 changes: 126 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@supabase/supabase-js": "^2.99.1",
"next": "16.1.6",
"react": "19.2.3",
"react-dom": "19.2.3"
Expand Down
Loading
Loading