簡體   English   中英

auth.currentUser.updateProfile 不是 function

[英]auth.currentUser.updateProfile is not a function

我正在嘗試更改用戶的用戶名和用戶配置文件 img,但它錯過了我導入的 function。 我嘗試過使用 auth.currentUser.updateProfile 但它無法將其識別為 function 我什至無法在 function 前面放置等待。 它在調用 doneHandle 時發生。 這里的身份驗證基本上是“const auth = getAuth(app);” 應用程序的初始化。

import React, { useContext, useState } from 'react';

import { AuthContext } from '../App';
import { updateProfile } from 'firebase/auth';

export default function Dashboard() {
  const { currentUser, auth } = useContext(AuthContext);
  const [content, setContent] = useState('');
  const [open, setOpen] = useState(false);
  const [dia, setDia] = useState('');

  const handleClickOpen = (e) => {
    setDia(e.target.value);
    setOpen(true);
  };

  const handleClose = () => {
    setOpen(false);
  };

  const doneHandle = (e) => {
    if (e.target.value === 'Profile') {
      auth.currentUser
        .updateProfile({
          displayName: content,
        })
        .then(function (error) {
          console.log(error);
        });
    } else {
      currentUser
        .updateProfile({
          photoURL: content,
        })
        .then(function (error) {
          console.log(error);
        });
    }
  };
  return (


<Removed some code that was not related to the ques>

        <Dialog open={open} onClose={handleClose}>
          <DialogContent>
            <DialogContentText>
              {dia === 'Profile'
                ? 'Enter your name down below.'
                : 'Please paste the direct url to the image. '}
            </DialogContentText>
            <TextField
              autoFocus
              margin='dense'
              id='name'
              type='email'
              fullWidth
              variant='standard'
              value={content}
              onChange={(e) => {
                setContent(e.target.value);
              }}
            />
          </DialogContent>
          <Button
            value={dia}
            onClick={(e) => {
              doneHandle(e);
            }}
          >
            Done
          </Button>
        </Dialog>
      </div>
    </div>
  );
}

You're importing updateProfile as a top-level function from the v9 modular SDK, but then try to invoke a updateProfile method on the user object - which is the namspaced syntax for the v8 SDK. 您不能只是混合和匹配這些語法。

更新用戶配置文件文檔中的代碼示例所示,您應該調用頂級 function 並將當前用戶作為 arguments 傳遞:

updateProfile(currentUser, {
  displayName: content
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM