// userinfo 테이블에서 필요한 컬럼만 선택적으로 가져오도록 수정
export const getUserInfo = async (id: number): Promise<Typedata['public']['Tables']['userinfo']['Row'] | null> => {
try {
const { data } = await supabase
.from('userinfo')
.select('id, name, email') // 필요한 컬럼만 선택
.eq('id', id)
.single();
return data || null;
} catch (error) {
console.error(error);
const AuthenticationLayer = ({ children }: { children: React.ReactNode }) => {
const dispatch = useDispatch();
useEffect(() => {
const authListener = supabase.auth.onAuthStateChange((event, session) => {
if (session?.user) {
getUserInfo(session.user.id)
.then((response) => dispatch(setUser(response)))
.catch((error) => {
console.error(error);
dispatch(setUser(null));
});
} else {
dispatch(setUser(null));
}
});
// clean up
return () => {
authListener.data.subscription.unsubscribe();
};
}, [dispatch]);
return children;
};
export default AuthenticationLayer;
import AuthenticationLayer from 'AuthenticationLayer';
import Router from './shared/Router';
function App() {
return (
<AuthenticationLayer>
<Router />
</AuthenticationLayer>
);
}
export default App;