feat: Upgrade to Next.js 16.1 & React 19.2, migrate to Supabase SSR with async client handling
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
'use server';
|
||||
|
||||
import { createServerComponentClient } from '@supabase/auth-helpers-nextjs';
|
||||
import { cookies } from 'next/headers';
|
||||
import { createClient } from '@/lib/supabase/server';
|
||||
|
||||
interface TrackApiUsageParams {
|
||||
userId: string;
|
||||
@@ -33,7 +32,7 @@ const GOOGLE_SEARCH_DAILY_LIMIT = 80;
|
||||
*/
|
||||
export async function trackApiUsage(params: TrackApiUsageParams): Promise<{ success: boolean; error?: string }> {
|
||||
try {
|
||||
const supabase = createServerComponentClient({ cookies });
|
||||
const supabase = await createClient();
|
||||
|
||||
// Security check: Ensure user is only tracking their own usage
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
@@ -69,7 +68,7 @@ export async function trackApiUsage(params: TrackApiUsageParams): Promise<{ succ
|
||||
*/
|
||||
export async function checkDailyLimit(apiType: 'google_search' | 'gemini_ai'): Promise<DailyLimitCheck> {
|
||||
try {
|
||||
const supabase = createServerComponentClient({ cookies });
|
||||
const supabase = await createClient();
|
||||
|
||||
// Only enforce limit for Google Search
|
||||
if (apiType !== 'google_search') {
|
||||
@@ -114,7 +113,7 @@ export async function checkDailyLimit(apiType: 'google_search' | 'gemini_ai'): P
|
||||
*/
|
||||
export async function getUserApiStats(userId: string): Promise<ApiStats | null> {
|
||||
try {
|
||||
const supabase = createServerComponentClient({ cookies });
|
||||
const supabase = await createClient();
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('api_usage')
|
||||
@@ -152,7 +151,7 @@ export async function getUserApiStats(userId: string): Promise<ApiStats | null>
|
||||
*/
|
||||
export async function getGlobalApiStats(): Promise<ApiStats | null> {
|
||||
try {
|
||||
const supabase = createServerComponentClient({ cookies });
|
||||
const supabase = await createClient();
|
||||
|
||||
// Check if user is admin
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
@@ -197,7 +196,7 @@ export async function getGlobalApiStats(): Promise<ApiStats | null> {
|
||||
export async function checkIsAdmin(userId: string): Promise<boolean> {
|
||||
try {
|
||||
console.log('[checkIsAdmin] Checking admin status for user:', userId);
|
||||
const supabase = createServerComponentClient({ cookies });
|
||||
const supabase = await createClient();
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('admin_users')
|
||||
|
||||
Reference in New Issue
Block a user