인프런 커뮤니티 질문&답변

dev.jun28님의 프로필 이미지

작성한 질문수

만들면서 배우는 프론트엔드 DO IT 코딩 (Next.js, Typescript)

사용자 추가 API 구현

firebase store추가

해결된 질문

22.08.22 05:21 작성

·

338

0

async function signInWithGoogle(): Promise<void> {
const provider = new GoogleAuthProvider();
try {
const signInResult = await signInWithPopup(FirebaseClient.getInstance().Auth, provider);
if (signInResult.user) {
const resp = await fetch('/api/members.add', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
uid: signInResult.user.uid,
email: signInResult.user.email,
displayName: signInResult.user.displayName,
photoURL: signInResult.user.photoURL,
}),
});
console.info({ status: resp.status });
const respData = await resp.json();
console.info(respData);
}
} catch (err) {
console.error(err);
}

// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next';
import { FirebaseAdmin } from '../../models/firebase_admin';

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
const { uid, displayName, photoURL, email } = req.body;
if (uid === undefined || uid === null) {
return res.status(400).json({ result: false, message: 'uid가 누락되었습니다.' });
}
try {
const addResult = await FirebaseAdmin.getInstance().Firebase.collection('members').add({
uid,
email: email ?? '',
displayName: displayName ?? '',
photoURL: photoURL ?? '',
});
return res.status(200).json({ result: true, id: addResult });
} catch (error) {
console.error(error);
res.status(500).json({ result: false });
}


firebase 에 members가 추가가 안됩니다..
  code: 16,
  details: 'Failed to retrieve auth metadata with error: error:0909006C:PEM routines:get_name:no start line',
  metadata: Metadata { internalRepr: Map(0) {}, options: {} },
  note: 'Exception occurred in retry method that was not classified as transient'

stackoverflow 에서도 찾아보고 있는데 혹시 해결방법이 있을까요
}



}

답변 2

0

dev.jun28님의 프로필 이미지
dev.jun28
질문자

2022. 08. 22. 21:18

  1. 새로운 사용자 추가 되었습니다.

      2. 터미널에 찍히는 오류 입니다.

 

 

firebase 설정 테스트서버 쪽으로 안돌아가있던건지..

서버 설정 다시 하니까 작동 됩니다.

감사합니다.

0

totuworld님의 프로필 이미지
totuworld
지식공유자

2022. 08. 22. 18:30

Eli님 안녕하세요.

앞에서부터 진행이 잘 되지 않아 속상하셨겠네요.

 

어느 부분에서 안되시는지 확인이 필요해서 질문 몇가지 남깁니다.

1. 로그인을 진행하면 firebase authentication에 새로운 사용자가 추가되어 있나요?

2. 해당 에러는 브라우저에서 나는 건가요? 아니면 next.js를 실행한 터미널에 찍히는 오류인가요?

 

답변 남겨주시면 저도 단서를 얻을 수 있겠네요.