로그인 버튼 클릭시 auth/auth-domain-config-required 에러 발생
710
投稿した質問数 25
안녕하세요. 로그인 버튼 클릭시 콘솔창에 다음과 같은 에러가 발생합니다.

rebaseError: Firebase: Error (auth/auth-domain-config-required).
at createErrorInternal (index-16e22603.js:497:1)
at _assert (index-16e22603.js:503:1)
at getIframeUrl (index-16e22603.js:9318:1)
at _openIframe (index-16e22603.js:9343:1)
at async BrowserPopupRedirectResolver.initAndGetManager (index-16e22603.js:9609:1)
w
https://firebase.google.com/docs/reference/js/v8/firebase.auth.Auth
공식 문서를 보니 authDomain configuration is not provided 일때 발생하는 에러라고 합니다.
auth/auth-domain-config-required
Thrown if authDomain configuration is not provided when calling firebase.initializeApp(). Check Firebase Console for instructions on determining and passing that field.
아래는 로그인버튼 컴포넌트에 onClick입니다.
코드상에는 에러가 발생하지 않았습니다.
<GoogleLoginButton
onClick={() => {
signInWithPopup(FirebaseClient.getInstance().Auth, provider)
.then((result) => {
console.info(result.user);
})
.catch((error) => {
console.error(error);
});
}}
/>루트 폴더에 .env 파일도 잘 있구요 ㅜㅜ
아래는 루트 폴더에 next.config.js 파일입니다.
module.exports = {
reactStrictMode: true,
publicRuntimeConfig: {
publicApiKey: process.env.publicApiKey || '',
authDomain: process.env.FIREBASE_AUTH_HOST || '',
projectId: process.env.projectId || '',
},
};
로그인 버튼 컴포넌트도 강사님 코드와 일치합니다..
아래는 models/firebase_client.ts 입니다.
원인이 뭘까요!?
import { initializeApp, getApps } from 'firebase/app';
import { Auth, getAuth } from 'firebase/auth';
import getConfig from 'next/config';
const { publicRuntimeConfig } = getConfig();
/** 환경변수는 node.js이기 때문에 서버에서 사용할 수 있고, 클라이언트에서 바로 접근할 수 없기 때문에 config 설정을 해주고
* 아래처럼 가져와서 쓸 수 있도록 해준다.
*/
const FirebaseCredentials = {
apiKey: publicRuntimeConfig.apiKey,
authDomain: publicRuntimeConfig.authDomain,
projectId: publicRuntimeConfig.projectId,
};
/** Firebase의 Authentication 모듈을 사용하기 위해 FirebaseClient 클래스를 정의하는 코드 */
export default class FirebaseClient {
private static instance: FirebaseClient;
private auth: Auth;
/** 이미 초기화된 Firebase 애플리케이션이 있는지 검사하고, 없다면 FirebaseCredentials를 사용하여 Firebase 애플리케이션을 초기화 */
public constructor() {
/** 앱이 몇 개 있는지 찾는 것 */
const apps = getApps();
/** 앱이 한 번도 초기화되지 않았다면 초기화를 시작 */
if (apps.length === 0) {
console.info('firebase client init start');
initializeApp(FirebaseCredentials);
}
/** 초기화가 되었으면 Auth를 가져와서 할당 */
this.auth = getAuth();
console.info('firebase auth');
}
/** 인스턴스를 가져옴 */
public static getInstance(): FirebaseClient {
if (FirebaseClient.instance === undefined || FirebaseClient.instance === null) {
FirebaseClient.instance = new FirebaseClient();
}
return FirebaseClient.instance;
}
/** auth를 반환 */
public get Auth(): Auth {
return this.auth;
}
}
回答 1
0
자체 해결
에러 이후 코드 변경이 없었는데 오늘 다시 보니 동일한 코드임에도 불구하고 에러 메시지가 달랐습니다.
FirebaseError: Firebase: Error (auth/invalid-api-key).
firebase_client 파일에서 api 키에 대한 프로퍼티 이름을 수정하니까 문제가 해결되었습니다.
const FirebaseCredentials = {
apiKey: publicRuntimeConfig.publicApiKey,
authDomain: publicRuntimeConfig.authDomain,
projectId: publicRuntimeConfig.projectId,
};기존 강사님 코드와 100% 일치했고 publicRuntimeConfig뒤에 접근하는 속성만
publicRuntimeConfig.apiKey에서 publicRuntimeConfig.publicApiKey로 바꿨습니다.
firebase에서 업데이트를 한걸까요? 이유가 궁금합니다.
1
코드로만 놓고보면 환경변수는 publicRuntimeConfig.publicApiKey 이렇게 선언해놓고 사용할 때는 publicRuntimeConfig.apiKey, 요렇게 넣어서 체크하지 못한듯하네요!
post하는 경우에 uid 설정
0
139
1
vscode bgColor 바로 표시되기 설정방법 및 chakra-ui img src 설정관련
0
508
2
클래스 방식말고 (2)
0
327
1
클래스 방식말고
0
312
1
배포 후 오류
0
1150
3
const resp = await fetch(`/api/messages.list?uid=${uid}`)가 404에러가 뜹니다
0
438
1
localhost:3000/api/user.info/totuworld 404 에러가 뜹니다.
0
437
3
사용자를 찾을 수 없다.
0
378
1
2. 사용자 API 만들기 => 강의는 짧지만 백엔드 api 만드는 기본 내용 다 들어가 있음 주의하세요!!
0
379
1
toast 처리부터 오류발생
0
600
3
FirebaseError: Firebase: Error (auth/invalid-api-key).
0
1831
3
Vercel 배포 후 thumbnail api 에러 발생합니다.
0
707
1
[~~].toStr에 대해
0
248
1
firebase admin 환경 초기화 하는 부분 질문입니다.
0
406
1
/api/[screenName].ts API에 대해 문의드립니다.
0
340
1
구글 가입 버튼 오류: redirect_uri_mismatch
0
537
1
mac m1 node 14버전 설치 에러
0
642
1
전체 예제 소스좀 올려주세요
0
445
1
R_CONNECTION_TIMED_OUT 오류
0
625
1
@types/react를 인식하지 못하는 에러
0
2831
3
thunder client로 get 요청시 무한로딩
0
1157
1
firebase auth 인증 질문
0
1210
1
router 관련 질문입니다.
0
386
1
자동 줄바꿈
0
383
1

