簡體   English   中英

Firebase:錯誤(auth/admin-restricted-operation)

[英]Firebase: Error (auth/admin-restricted-operation)

我正在使用 reactjs 進行 firebase 身份驗證,但我無法做到。 它拋出錯誤, error message-> Firebase: Error (auth/admin-restricted-operation). 我怎么被限制了? 為什么它是管理員限制操作...我已經解決了很多問題,但並沒有真正幫助...我什至在 firebase 上創建了一個新項目,但問題仍然存在...

file: firebaseConfig.js

import { initializeApp } from "firebase/app";
import { getAuth } from 'firebase/auth'

const firebaseConfig = {
    apiKey: "xxxxx",
    authDomain: "xxxxx",
    projectId: "xxxxx",
    storageBucket: "xxxxx",
    messagingSenderId: "xxxxx",
    appId: "xxxxx",
    measurementId: "xxxxx"
};

const app = initializeApp(firebaseConfig)
export default app
export const auth = getAuth(app) 



file: signUp.js

import React, {useState} from 'react'
import { createUserWithEmailAndPassword } from 'firebase/auth'
import { auth } from '../../firebaseConfig'

//css module import 
import signupCard from './SignUp.module.css'

export const SignUp = props =>{

    //State....
    const [ credentials, setCredentials ] = useState({
        fnameRef: '', 
        snameRef:'',
        phoneRef: '',
        cityRef: '',
        dobRef: '',
        emailRef: '',
        passwordRef: '',
        passwordConfirmationRef: ''
    })

    const signupHandler = async (event) =>{
        event.preventDefault()

        if(credentials.emailRef === '' && credentials.passwordRef === ''){
            console.log('empty fields!!')
        }else{
            try{
                const user = await createUserWithEmailAndPassword(auth, credentials.emailRef, credentials.passwordRef)
                console.log(user)
            }catch(error){
                console.log(error)
            }
        }
        
        
    }

    const backHandler = () => {
        props.backButtonDetails(true)
    }

    return(
        <React.Fragment>
            <div className = {signupCard.signupContainer}>
                
                <form onSubmit={signupHandler}>
                    <div className = {signupCard.signupFormFirst} >
                    <button onClick={backHandler} > back </button>
                        <span className = {signupCard.branding1}>SnowChild</span>
                        <hr className = {signupCard.hrTag}/>
                        <input type = 'text' className = {signupCard.fname} placeholder = 'firstname' id = 'Fname' onChange = {(event) => setCredentials({fnameRef: event.target.value})}/>
                        <input type = 'text' className = {signupCard.sname} placeholder = 'surname' id = 'Sname' onChange = {(event) => setCredentials({snameRef: event.target.value})}/>
                        <input type = 'text' className = {signupCard.phone} placeholder = 'phone' id = 'contact' onChange = {(event) => setCredentials({phoneRef: event.target.value})}/>
                        <input type = 'text' className = {signupCard.city} placeholder = 'city' id = 'Where' onChange = {(event) => setCredentials({cityRef: event.target.value})} />
                        <span className = {signupCard.dateString} >Date of birth</span>
                        <input type = 'date' className = {signupCard.dob} id = 'birthdate' onChange = {(event) => setCredentials({dobRef: event.target.value})}/>
                        <hr className = {signupCard.hrTag}  style = {{margin: '20px 0 10px 0'}}/> 
                    </div>
                    <div className = {signupCard.signupFormSecond}>
                        <hr className = {signupCard.hrTag} />
                        <input type = 'email' placeholder = 'Email' className = {signupCard.UNF} id = 'email' onChange = {(event) => setCredentials({emailRef: event.target.value})}/>
                        <input type = 'password' placeholder = 'Password' className = {signupCard.PWD} id = 'password' onChange = {(event) => setCredentials({passwordRef: event.target.value})}/>
                        <input type = 'password' placeholder = 'confirmPassword' className = {signupCard.PWD} id = 'passwordConfirmation' onChange = {(event) => setCredentials({passwordConfirmationRef: event.target.value})}/>
                        <hr className = {signupCard.hrTag} style = {{marginTop: '10px'}}/>
                        <button type = 'submit' className={signupCard.signupButton}> Sign up </button>
                    </div>
                </form>
            </div>
            </React.Fragment>
    )
}



我究竟做錯了什么??
錯誤在此處輸入圖像描述

我認為這可能與以下3件事有關。

有人建議Firebase規則在這個類似的管理員操作限制答案中沒有正確設置

我為你所做的所有其他主題和研究中最大的建議,可能是錯誤的答案在這里找到匿名簽名 firebase

另一個答案與 Firebase 版本控制和在Dandotwaves 答案中使用的代碼有關

這是 Dandotwave 發表的那篇文章中的代碼:

import { firebase } from "@firebase/app";

import { initializeApp } from "firebase/app";

import { getAuth, onAuthStateChanged } from "firebase/auth";

const firebaseConfig =  {
  apiKey: "xxx",
  authDomain: "xxx",
  projectId: "xxx",
  storageBucket: "xxx",
  messagingSenderId: "xxx",
  appId: "xxx",
};

const app = initializeApp(firebaseConfig);
const auth = getAuth();

您正在使用

const app = initializeApp(firebaseConfig)
export default app
export const auth = getAuth(app) 

所以我找到了答案,但我不知道背后的原因。 它更像是一個熱門和試用的答案....

前:

const [ credentials, setCredentials ] = useState({
        fnameRef: '', 
        snameRef:'',
        phoneRef: '',
        cityRef: '',
        dobRef: '',
        emailRef: '',
        passwordRef: '',
        passwordConfirmationRef: ''
    })

后:

 const [currentUser, setCurrentUser ] = useState('')
    const [ credentials, setCredentials ] = useState({
        fnameRef: '', 
        snameRef:'',
        phoneRef: '',
        cityRef: '',
        dobRef: ''
    })
    const [ emailRef, setEmailRef ] = useState('')
    const [ passwordRef, setPasswordRef] = useState('')

所以我將 ```emailRef 和 passwordRef``` 轉換為獨立的 ```State Variables``` 但是我知道這背后的解釋......但是是的它確實有效,現在正在創建用戶......

暫無
暫無

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

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