Skip to content

Commit 94319fc

Browse files
SUNSUN
authored andcommitted
fix: 빌드 에러 해결
1 parent d5b50f2 commit 94319fc

7 files changed

Lines changed: 87 additions & 20 deletions

File tree

apps/client/src/api/album.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import { api } from "@/api";
1+
import { api, isClientApiConfigured } from "@/api";
22
import { AlbumType, IGetAlbumListResponse, IGetAlbumRequest, IGetAlbumResponse } from "type";
33

44
export const getAlbumList = async ({ type, page, size }: { type: AlbumType; page: number; size: number }) => {
5+
if (!isClientApiConfigured()) {
6+
return { albums: [], totalAlbums: 0 };
7+
}
58
const { data } = await api.get<IGetAlbumListResponse>("/albums", {
69
params: { type, page, size },
710
});
811
return data;
912
};
1013

1114
export const getAlbum = async ({ id }: IGetAlbumRequest) => {
15+
if (!isClientApiConfigured()) {
16+
throw new Error("Client API base URL is not configured");
17+
}
1218
const { data } = await api.get<IGetAlbumResponse>(`/albums/${id}`);
1319

1420
return data;

apps/client/src/api/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import axios from "axios";
22

3+
const origin = process.env.NEXT_PUBLIC_AXIOS_DEFAULT_BASEURL?.replace(/\/$/, "") ?? "";
4+
5+
export const isClientApiConfigured = () => origin.length > 0;
6+
37
export const api = axios.create({
4-
baseURL: `${process.env.NEXT_PUBLIC_AXIOS_DEFAULT_BASEURL}/api/client`,
8+
baseURL: origin ? `${origin}/api/client` : "",
59
});

apps/client/src/api/youtube.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import { IGetLiveResponse } from "type/src/youtube";
2-
import { api } from ".";
2+
import { api, isClientApiConfigured } from ".";
33
import { IGetYoutubeResponse, YoutubeType } from "type";
44

55
export interface IGetYoutbeRequest {
66
videoType: YoutubeType;
77
videoCount?: number;
88
}
99
export const getLive = async () => {
10+
if (!isClientApiConfigured()) {
11+
return { live: { url: "", updatedAt: 0 } };
12+
}
1013
const { data } = await api.get<IGetLiveResponse>("/live");
1114
return data;
1215
};
1316

1417
export const getYoutube = async (type: YoutubeType) => {
18+
if (!isClientApiConfigured()) {
19+
return { videos: [], totalVideos: 0 };
20+
}
1521
const { data } = await api.get<IGetYoutubeResponse>("/videos", {
1622
params: { type },
1723
});

apps/client/src/constants/innerMenus/about.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const officerType: IOfficerType[] = [
2222
{ label: "retired", type: "원로목사" },
2323
{ label: "senior", type: "담임목사" },
2424
{ label: "associate", type: "목사" },
25-
{ label: "cooperativePastor", type: "협동목사" },
25+
{ label: "otherAssociate", type: "협동목사" },
2626
{ label: "evangelist", type: "전도사" },
2727
{ label: "missionary", type: "선교사" },
2828
{ label: "elder", type: "장로" },

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"scripts": {
55
"build": "turbo build",
6-
"build:client": "turbo run build --filter=client",
6+
"build:client": "dotenv -- turbo run build --filter=client",
77
"build:client-renewal": "turbo run build --filter=client-renewal",
88
"build:admin": "turbo run build --filter=admin",
99
"dev": "turbo dev",

packages/firebase/firebase.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
// Import the functions you need from the SDKs you need
2-
import { initializeApp } from "firebase/app";
1+
import { getApps, initializeApp, type FirebaseApp } from "firebase/app";
32

4-
// TODO: Add SDKs for Firebase products that you want to use
5-
// https://firebase.google.com/docs/web/setup#available-libraries
6-
7-
// Your web app's Firebase configuration
8-
const firebaseConfig = {
3+
const envConfig = {
94
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
105
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
116
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
@@ -14,5 +9,36 @@ const firebaseConfig = {
149
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
1510
};
1611

17-
// Initialize Firebase
18-
export const firebase = initializeApp(firebaseConfig);
12+
/** next build 등 환경 변수가 없을 때 initializeApp만 통과시키기 위한 자리 표시자(실제 Auth/네트워크 호출은 하지 않음). */
13+
const BUILD_PLACEHOLDER_CONFIG = {
14+
apiKey: "AIzaSy0000000000000000000000000000000",
15+
authDomain: "build-placeholder.firebaseapp.com",
16+
projectId: "build-placeholder",
17+
storageBucket: "build-placeholder.appspot.com",
18+
messagingSenderId: "000000000000",
19+
appId: "1:000000000000:web:0000000000000000000000",
20+
} as const;
21+
22+
function resolveConfig() {
23+
if (envConfig.apiKey) {
24+
return {
25+
apiKey: envConfig.apiKey,
26+
authDomain: envConfig.authDomain ?? "",
27+
projectId: envConfig.projectId ?? "",
28+
storageBucket: envConfig.storageBucket,
29+
messagingSenderId: envConfig.messagingSenderId,
30+
appId: envConfig.appId,
31+
};
32+
}
33+
return { ...BUILD_PLACEHOLDER_CONFIG };
34+
}
35+
36+
export function getFirebaseApp(): FirebaseApp {
37+
const existing = getApps()[0];
38+
if (existing) {
39+
return existing;
40+
}
41+
return initializeApp(resolveConfig());
42+
}
43+
44+
export const firebase = getFirebaseApp();

packages/firebase/src/auth.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
1-
import { createUserWithEmailAndPassword, getAuth, signInWithEmailAndPassword } from "firebase/auth";
2-
import { firebase } from "../firebase";
1+
import {
2+
createUserWithEmailAndPassword,
3+
getAuth,
4+
signInWithEmailAndPassword,
5+
type Auth,
6+
} from "firebase/auth";
37

4-
export const auth = getAuth(firebase);
8+
import { getFirebaseApp } from "../firebase";
9+
10+
let authInstance: Auth | undefined;
11+
12+
function getAuthSingleton(): Auth {
13+
if (!authInstance) {
14+
authInstance = getAuth(getFirebaseApp());
15+
}
16+
return authInstance;
17+
}
18+
19+
/** next build SSG 시 모듈 로드만으로 getAuth가 돌지 않도록 지연 초기화합니다. */
20+
export const auth = new Proxy({} as Auth, {
21+
get(_target, prop, _receiver) {
22+
const instance = getAuthSingleton();
23+
const value = Reflect.get(instance as object, prop, instance);
24+
if (typeof value === "function") {
25+
return (value as (...args: unknown[]) => unknown).bind(instance);
26+
}
27+
return value;
28+
},
29+
});
530

631
// FIXME: test
732
export const getTest = () => {
8-
return auth.name;
33+
return getAuthSingleton().name;
934
};
1035

1136
export const postLogin = async ({ email, password }: { email: string; password: string }) => {
12-
const userCredential = await signInWithEmailAndPassword(auth, email, password);
37+
const userCredential = await signInWithEmailAndPassword(getAuthSingleton(), email, password);
1338
return userCredential;
1439
};
1540

1641
export const postSignup = async ({ email, password }: { email: string; password: string }) => {
17-
const userCredential = await createUserWithEmailAndPassword(auth, email, password);
42+
const userCredential = await createUserWithEmailAndPassword(getAuthSingleton(), email, password);
1843
return userCredential.user;
1944
};

0 commit comments

Comments
 (0)