Investigate table creation API
Explore the possibility of creating tables directly via the Supabase API.
This commit is contained in:
@@ -3,6 +3,7 @@ import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useToast } from "@/hooks/useToast.wrapper";
|
||||
import { useAuth } from "@/contexts/auth";
|
||||
import { createRequiredTables } from "@/lib/supabase/setup";
|
||||
|
||||
export function useLogin() {
|
||||
const [email, setEmail] = useState("");
|
||||
@@ -10,6 +11,7 @@ export function useLogin() {
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [loginError, setLoginError] = useState<string | null>(null);
|
||||
const [isSettingUpTables, setIsSettingUpTables] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
const { toast } = useToast();
|
||||
const { signIn } = useAuth();
|
||||
@@ -30,7 +32,7 @@ export function useLogin() {
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
const { error } = await signIn(email, password);
|
||||
const { error, user } = await signIn(email, password);
|
||||
|
||||
if (error) {
|
||||
console.error("로그인 실패:", error);
|
||||
@@ -61,6 +63,23 @@ export function useLogin() {
|
||||
variant: "destructive"
|
||||
});
|
||||
} else {
|
||||
// 로그인 성공 시 필요한 테이블 설정
|
||||
try {
|
||||
setIsSettingUpTables(true);
|
||||
const { success, message } = await createRequiredTables();
|
||||
|
||||
if (success) {
|
||||
console.log("테이블 설정 성공:", message);
|
||||
} else {
|
||||
console.warn("테이블 설정 문제:", message);
|
||||
// 테이블 설정 실패해도 로그인은 진행
|
||||
}
|
||||
} catch (setupError) {
|
||||
console.error("테이블 설정 중 오류:", setupError);
|
||||
} finally {
|
||||
setIsSettingUpTables(false);
|
||||
}
|
||||
|
||||
navigate("/");
|
||||
}
|
||||
} catch (err: any) {
|
||||
@@ -86,6 +105,7 @@ export function useLogin() {
|
||||
showPassword,
|
||||
setShowPassword,
|
||||
isLoading,
|
||||
isSettingUpTables,
|
||||
loginError,
|
||||
setLoginError,
|
||||
handleLogin
|
||||
|
||||
Reference in New Issue
Block a user