是否有一个带有 firebase 的提示图书馆?

发布于 2025-02-13 22:59:51 字数 1922 浏览 7 评论 0原文

我正在尝试学习如何从提供的 firebase auth 中删除用户,但是当我单击 html 上的删除按钮时,它给了我 Uncaught ReferenceError: promptForCredentials is not defined ​ 如果我想在任何地方导入它,我找不到任何信息。我正在使用普通的香草 JavaScript。

这是我的代码:

我的 HTML 包含脚本:

<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-database.js"></script>

JavaScript:

const firebaseConfig = {//my app information}
firebase.initializeApp(firebaseConfig);

const auth = firebase.auth();
const database = firebase.database();
const fname = document.querySelector('#fname');
    const lname = document.querySelector('#lname');
    const email = document.querySelector('#email');
    const password = document.querySelector('#password');
    const confirm_password = document.querySelector('#confirmpassword');
    const deleteConfirmed = document.querySelector('.deleteConfirmed');
    const passConfirmed = document.querySelector('#deletePass');

    auth.onAuthStateChanged(user => {
      if(user) {
        const user = auth.currentUser
        const database_ref = database.ref('users/' + user.uid).on('value', (snapshot) => {
          fname.value = snapshot.val().first_name;
          lname.value = snapshot.val().last_name;
          email.value = snapshot.val().email;
        });

        deleteConfirmed.addEventListener('click', () => {
          const credential = promptForCredentials();
          user.reauthenticateWithCredential(credential).then(() => {
            // User re-authenticated.
          }).catch((error) => {
            // An error ocurred
            // ...
          });
        })
            
      } else {
        location.href = "/login";
      }
      
    });

I am trying to learn how to delete users from the Firebase Auth provided, but when I click on the delete button on my html it gives me Uncaught ReferenceError: promptForCredentials is not defined
I can't find any information on if I am suppose to import it anywhere. I'm using plain vanilla javascript.

Here is my code:

my html includes for scripts:

<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-database.js"></script>

javascript:

const firebaseConfig = {//my app information}
firebase.initializeApp(firebaseConfig);

const auth = firebase.auth();
const database = firebase.database();
const fname = document.querySelector('#fname');
        const lname = document.querySelector('#lname');
        const email = document.querySelector('#email');
        const password = document.querySelector('#password');
        const confirm_password = document.querySelector('#confirmpassword');
        const deleteConfirmed = document.querySelector('.deleteConfirmed');
        const passConfirmed = document.querySelector('#deletePass');

        auth.onAuthStateChanged(user => {
            if(user) {
                const user = auth.currentUser
                const database_ref = database.ref('users/' + user.uid).on('value', (snapshot) => {
                    fname.value = snapshot.val().first_name;
                    lname.value = snapshot.val().last_name;
                    email.value = snapshot.val().email;
                });

                deleteConfirmed.addEventListener('click', () => {
                    const credential = promptForCredentials();
                    user.reauthenticateWithCredential(credential).then(() => {
                      // User re-authenticated.
                    }).catch((error) => {
                      // An error ocurred
                      // ...
                    });
                })
                        
            } else {
                location.href = "/login";
            }
            
        });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神魇的王 2025-02-20 22:59:53

看起来您从firebase文档中复制代码以重新验证用户,这表明:

const user = firebase.auth().currentUser;

// TODO(you): prompt the user to re-provide their sign-in credentials
const credential = promptForCredentials();

user.reauthenticateWithCredential(credential).then(() => {
  // User re-authenticated.
}).catch((error) => {
  // An error occurred
  // ...
});

todo在那里意味着 you 必须实现该凭据的提示用户以任何方式适用于您的应用程序,然后将其传递到recealenticateWithCredential api。

It looks like you copied code from the Firebase documentation on re-authenticating a user, which shows:

const user = firebase.auth().currentUser;

// TODO(you): prompt the user to re-provide their sign-in credentials
const credential = promptForCredentials();

user.reauthenticateWithCredential(credential).then(() => {
  // User re-authenticated.
}).catch((error) => {
  // An error occurred
  // ...
});

That TODO there means that you have to implement the prompt for the credentials of the user in whatever way works for your app, and then pass them to the reauthenticateWithCredential API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文