繁体   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