Configure Supabase environment variables

Sets Supabase URL and anon key using environment variables.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 06:28:59 +00:00
parent 73d2558ae7
commit 5089838a57
2 changed files with 93 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
// Core synchronization settings utilities
import { supabase } from '@/lib/supabase';
/**
* Check if synchronization is enabled in local storage
@@ -43,12 +44,92 @@ export const setLastSyncTime = (): void => {
}
};
// 모든 데이터 동기화 함수
export const syncAllData = async (userId: string): Promise<void> => {
if (!userId) {
throw new Error('사용자 ID가 필요합니다');
}
try {
// 로컬 트랜잭션 데이터 가져오기
const transactionsJSON = localStorage.getItem('transactions');
const transactions = transactionsJSON ? JSON.parse(transactionsJSON) : [];
// 예산 데이터 가져오기
const budgetDataJSON = localStorage.getItem('budgetData');
const budgetData = budgetDataJSON ? JSON.parse(budgetDataJSON) : {};
// 카테고리 예산 가져오기
const categoryBudgetsJSON = localStorage.getItem('categoryBudgets');
const categoryBudgets = categoryBudgetsJSON ? JSON.parse(categoryBudgetsJSON) : {};
// 트랜잭션 데이터 동기화
for (const transaction of transactions) {
// 이미 동기화된 데이터인지 확인 (transaction_id로 확인)
const { data: existingData } = await supabase
.from('transactions')
.select('*')
.eq('transaction_id', transaction.id)
.eq('user_id', userId);
// 존재하지 않는 경우에만 삽입
if (!existingData || existingData.length === 0) {
await supabase.from('transactions').insert({
user_id: userId,
title: transaction.title,
amount: transaction.amount,
date: transaction.date,
category: transaction.category,
type: transaction.type,
transaction_id: transaction.id
});
}
}
// 예산 데이터 동기화
await supabase.from('budget_data').upsert({
user_id: userId,
data: budgetData,
updated_at: new Date().toISOString()
});
// 카테고리 예산 동기화
await supabase.from('category_budgets').upsert({
user_id: userId,
data: categoryBudgets,
updated_at: new Date().toISOString()
});
// 마지막 동기화 시간 업데이트
setLastSyncTime();
console.log('모든 데이터가 성공적으로 동기화되었습니다');
} catch (error) {
console.error('데이터 동기화 중 오류 발생:', error);
throw error;
}
};
// 초기화 함수 추가
export const initSyncSettings = (): void => {
try {
if (localStorage.getItem('syncEnabled') === null) {
localStorage.setItem('syncEnabled', 'false');
}
// Supabase 연결 테스트
(async () => {
try {
const { data, error } = await supabase.auth.getUser();
if (error) {
console.warn('Supabase 연결 테스트 실패:', error.message);
} else {
console.log('Supabase 연결 테스트 성공:', data.user ? '사용자 로그인됨' : '사용자 로그인 필요');
}
} catch (testError) {
console.error('Supabase 연결 테스트 중 예외 발생:', testError);
}
})();
} catch (error) {
console.error('동기화 설정 초기화 중 오류:', error);
}