Files
zellyy-finance/src/hooks/useTableSetup.ts
gpt-engineer-app[bot] 9ab2bf722a Refactor useLogin hook
Refactor the useLogin hook to separate login and table setup logic for better maintainability.
2025-03-15 13:11:33 +00:00

48 lines
1.3 KiB
TypeScript

import { useState } from "react";
import { useToast } from "@/hooks/useToast.wrapper";
import { createRequiredTables } from "@/lib/supabase/setup";
/**
* Supabase 테이블 설정을 처리하는 커스텀 훅
*/
export function useTableSetup() {
const [isSettingUpTables, setIsSettingUpTables] = useState(false);
const { toast } = useToast();
/**
* 로그인 성공 후 필요한 테이블을 설정합니다.
*/
const setupTables = async (): Promise<boolean> => {
try {
setIsSettingUpTables(true);
const { success, message } = await createRequiredTables();
if (success) {
console.log("테이블 설정 성공:", message);
return true;
} else {
console.warn("테이블 설정 문제:", message);
// 사용자에게 경고 표시 (선택적)
toast({
title: "테이블 설정 문제",
description: "일부 테이블 설정에 문제가 있었지만, 기본 기능은 사용할 수 있습니다.",
variant: "default"
});
// 테이블 설정 실패해도 로그인은 진행
return false;
}
} catch (setupError) {
console.error("테이블 설정 중 오류:", setupError);
return false;
} finally {
setIsSettingUpTables(false);
}
};
return {
isSettingUpTables,
setupTables
};
}