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

@@ -2,12 +2,14 @@
import { createClient } from '@supabase/supabase-js'; import { createClient } from '@supabase/supabase-js';
// Supabase 온프레미스 URL과 anon key 설정 // Supabase 온프레미스 URL과 anon key 설정
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL || 'YOUR_SUPABASE_URL'; // 환경 변수를 우선적으로 사용하되, 하드코딩된 값을 기본값으로 설정
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY || 'YOUR_SUPABASE_ANON_KEY'; const supabaseUrl = import.meta.env.VITE_SUPABASE_URL || 'https://xguihxuzqibwxjnimxev.supabase.co';
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhndWloeHV6cWlid3hqbmlteGV2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NzUwOTQ4MzUsImV4cCI6MTk5MDY3MDgzNX0.0PMlOxtKL4O9GGZuAP_Xl4f-Tut1qOnW4bNEmAtoB8w';
// 유효한 URL이 설정되었는지 확인 (기본값을 그대로 사용 중인지 체크) // 유효한 URL이 설정되었는지 확인
const isValidUrl = supabaseUrl !== 'YOUR_SUPABASE_URL' && const isValidUrl = supabaseUrl && supabaseAnonKey &&
supabaseAnonKey !== 'YOUR_SUPABASE_ANON_KEY'; !supabaseUrl.includes('YOUR_SUPABASE_URL') &&
!supabaseAnonKey.includes('YOUR_SUPABASE_ANON_KEY');
let supabaseClient; let supabaseClient;
@@ -20,9 +22,12 @@ try {
}, },
}); });
// Supabase 연결 확인 // Supabase 연결 로그
console.log('Supabase 클라이언트가 생성되었습니다.');
// 유효성 검사 로그
if (!isValidUrl) { if (!isValidUrl) {
console.warn('Supabase URL이나 Anon Key가 설정되지 않았습니다. 온프레미스 설정을 확인해주세요.'); console.warn('경고: 유효하지 않은 Supabase URL 또는 Anon Key가 감지되었습니다.');
} }
} catch (error) { } catch (error) {
console.error('Supabase 클라이언트 생성 오류:', error); console.error('Supabase 클라이언트 생성 오류:', error);

View File

@@ -1,5 +1,6 @@
// Core synchronization settings utilities // Core synchronization settings utilities
import { supabase } from '@/lib/supabase';
/** /**
* Check if synchronization is enabled in local storage * 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 => { export const initSyncSettings = (): void => {
try { try {
if (localStorage.getItem('syncEnabled') === null) { if (localStorage.getItem('syncEnabled') === null) {
localStorage.setItem('syncEnabled', 'false'); 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) { } catch (error) {
console.error('동기화 설정 초기화 중 오류:', error); console.error('동기화 설정 초기화 중 오류:', error);
} }