
getmyuid 함수를 사용할 때는 Firebase Authentication의 인증 상태가 활성화되어 있어야 합니다.
오류가 발생하는 경우, getUid 함수를 사용하는 대신 getAuth().currentUser.uid를 사용하거나, 사용자의 인증 상태를 확인하여 인증이 완료되었는지 확인하는 로직을 추가하는 것이 좋습니다.
위 코드에서 오류가 발생하는 이유는 getUid 함수가 deprecated되었으며, 대신 getAuth().currentUser.uid를 사용해야 합니다.
오류를 해결하기 위해 코드를 수정하여 getAuth().currentUser.uid를 사용하도록 변경할 수 있습니다.
#hostingforum.kr
javascript
import { getAuth } from 'firebase/auth';
const auth = getAuth();
const uid = auth.currentUser.uid;
console.log(uid);
또한, 사용자의 인증 상태를 확인하여 인증이 완료되었는지 확인하는 로직을 추가하는 것이 좋습니다.
#hostingforum.kr
javascript
import { getAuth } from 'firebase/auth';
const auth = getAuth();
auth.onAuthStateChanged((user) => {
if (user) {
const uid = user.uid;
console.log(uid);
} else {
console.log('인증이 완료되지 않았습니다.');
}
});
2025-06-29 04:06