我正在嘗試學習反應,并且作為學習的一部分,我試圖通過反應創建電子商務應用程式。這是我的代碼。
我在控制臺中收到一條錯誤訊息,我也在附加螢屏截圖。請幫助解決這個問題。
我已經嘗試了 firebase 的檔案,并且正在使用 firebase SDK 8.3 版。
import React, { useContext, useState } from 'react'
import FirebaseContext from '../../store/FirebaseContext'
import {useHistory} from "react-router-dom"
import "./SignUp.css"
function SignUp() {
const history=useHistory()
const [firstname,setFirstname]=useState('')
const [lastname,setLastname]=useState('')
const [email,setEmail]=useState('')
const [mobile,setMobile]=useState('')
const [password,setPassword]=useState('')
const {firebase} =useContext(FirebaseContext)
const handleSubmit=(e)=>{
e.preventDefault()
firebase.auth().createUserWithEmailAndPassword(email,password).then((result)=>{
result.user.updateProfile({displayName:firstname}).then(()=>{
firebase.firestore().collection('user').doc("one").set({
id:result.user.uid,
username:firstname,
firstname:firstname,
lastname:lastname,
phone:mobile
})
.then(()=>{
history.push("/login")
})
})
})
}
return (
<div>
<div className='signup-parent'>
<img alt="signup-logo" className="signup-logo"src='https://t4.ftcdn.net/jpg/03/77/48/55/360_F_377485593_QHN6cjoNsNdOBoJNOwVRlFcHyZ0M9n3P.jpg'/>
<form onSubmit={handleSubmit}>
<input className='input' value={firstname} onChange={(e)=>setFirstname(e.target.value)}
type="text" id="fname" placeholder="John" name='name'/>
<br />
<br/>
<input className='input'value={lastname} onChange={(e)=>setLastname(e.target.value)}
type="text" id="lname" placeholder="Smith" name='name'/>
<br/>
<br/>
<input className='input' value={email} onChange={(e)=>setEmail(e.target.value)}
type="email" id="email" placeholder="[email protected]" name='email'/>
<br/>
<br/>
<input className='input' value={mobile} onChange={(e)=>setMobile(e.target.value)}
type="number" id="mobile" placeholder="1234567" name='mobile'/>
<br/>
<br/>
<input className='input' value={password} onChange={(e)=>setPassword(e.target.value)}
type="password" id="password" placeholder='*******' name='password'/>
<br/>
<br/>
<br/>
<button className='signup-button' type='submit'>SignUp</button>
</form>
<a className='login-from-signup' href='/login'>Login</a>
</div>
</div>
)
}
export default SignUp
[1]: https://i.stack.imgur.com/BkFbz.png
文本形式的錯誤訊息
Uncaught (in promise) FirebaseError: Missing or insufficient permissions.
at new e (prebuilt-3c03a633-33a12d73.js:210:1)
at prebuilt-3c03a633-33a12d73.js:11566:1
at Y.<anonymous> (prebuilt-3c03a633-33a12d73.js:11508:1)
at tb (index.esm.js:728:1)
at E (index.esm.js:682:1)
at push../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js.Z.sa (index.esm.js:2666:1)
at qc (index.esm.js:1412:1)
at sc (index.esm.js:1264:1)
at push../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js.h.Ca (index.esm.js:1241:1)
at push../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js.h.Xa (index.esm.js:1196:1)
at tb (index.esm.js:728:1)
at E (index.esm.js:682:1)
at zd (index.esm.js:2041:1)
at push../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js.h.Ua (index.esm.js:2037:1)
at push../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js.h.za (index.esm.js:2033:1)
e @ prebuilt-3c03a633-33a12d73.js:210
(anonymous) @ prebuilt-3c03a633-33a12d73.js:11566
(anonymous) @ prebuilt-3c03a633-33a12d73.js:11508
tb @ index.esm.js:728
E @ index.esm.js:682
push../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js.Z.sa @ index.esm.js:2666
qc @ index.esm.js:1412
sc @ index.esm.js:1264
push../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js.h.Ca @ index.esm.js:1241
push../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js.h.Xa @ index.esm.js:1196
tb @ index.esm.js:728
E @ index.esm.js:682
zd @ index.esm.js:2041
push../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js.h.Ua @ index.esm.js:2037
push../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js.h.za @ index.esm.js:2033
Promise.then (async)
(anonymous) @ SignUp.js:29
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
a.onsuccess @ auth.esm.js:6465
IndexedDB (async)
(anonymous) @ auth.esm.js:6509
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
a.onsuccess @ auth.esm.js:6465
IndexedDB (async)
(anonymous) @ auth.esm.js:6485
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
a.onsuccess @ auth.esm.js:6465
IndexedDB (async)
(anonymous) @ auth.esm.js:6481
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
(anonymous) @ auth.esm.js:5177
(anonymous) @ auth.esm.js:5101
Dd @ auth.esm.js:2082
push../node_modules/@firebase/auth/dist/auth.esm.js.H.dispatchEvent @ auth.esm.js:2034
li @ auth.esm.js:4704
push../node_modules/@firebase/auth/dist/auth.esm.js.k.Jc @ auth.esm.js:4659
push../node_modules/@firebase/auth/dist/auth.esm.js.k.Vb @ auth.esm.js:4655
XMLHttpRequest.send (async)
ei @ auth.esm.js:4613
push../node_modules/@firebase/auth/dist/auth.esm.js.Ii.u @ auth.esm.js:5112
Si @ auth.esm.js:5077
(anonymous) @ auth.esm.js:5176
D @ auth.esm.js:1399
Yi @ auth.esm.js:5175
(anonymous) @ auth.esm.js:5662
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
a.onsuccess @ auth.esm.js:6465
IndexedDB (async)
(anonymous) @ auth.esm.js:6509
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
a.onsuccess @ auth.esm.js:6465
IndexedDB (async)
(anonymous) @ auth.esm.js:6485
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
a.onsuccess @ auth.esm.js:6465
IndexedDB (async)
(anonymous) @ auth.esm.js:6481
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
(anonymous) @ auth.esm.js:5177
(anonymous) @ auth.esm.js:5101
Dd @ auth.esm.js:2082
push../node_modules/@firebase/auth/dist/auth.esm.js.H.dispatchEvent @ auth.esm.js:2034
li @ auth.esm.js:4704
push../node_modules/@firebase/auth/dist/auth.esm.js.k.Jc @ auth.esm.js:4659
push../node_modules/@firebase/auth/dist/auth.esm.js.k.Vb @ auth.esm.js:4655
XMLHttpRequest.send (async)
ei @ auth.esm.js:4613
push../node_modules/@firebase/auth/dist/auth.esm.js.Ii.u @ auth.esm.js:5112
Si @ auth.esm.js:5077
(anonymous) @ auth.esm.js:5176
D @ auth.esm.js:1399
Yi @ auth.esm.js:5175
(anonymous) @ auth.esm.js:5662
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
(anonymous) @ auth.esm.js:5177
(anonymous) @ auth.esm.js:5101
Dd @ auth.esm.js:2082
push../node_modules/@firebase/auth/dist/auth.esm.js.H.dispatchEvent @ auth.esm.js:2034
li @ auth.esm.js:4704
push../node_modules/@firebase/auth/dist/auth.esm.js.k.Jc @ auth.esm.js:4659
push../node_modules/@firebase/auth/dist/auth.esm.js.k.Vb @ auth.esm.js:4655
XMLHttpRequest.send (async)
ei @ auth.esm.js:4613
push../node_modules/@firebase/auth/dist/auth.esm.js.Ii.u @ auth.esm.js:5112
Si @ auth.esm.js:5077
(anonymous) @ auth.esm.js:5176
D @ auth.esm.js:1399
Yi @ auth.esm.js:5175
(anonymous) @ auth.esm.js:5662
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
a.onsuccess @ auth.esm.js:6465
IndexedDB (async)
(anonymous) @ auth.esm.js:6509
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
a.onsuccess @ auth.esm.js:6465
IndexedDB (async)
(anonymous) @ auth.esm.js:6509
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
a.onsuccess @ auth.esm.js:6465
IndexedDB (async)
(anonymous) @ auth.esm.js:6485
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
a.onsuccess @ auth.esm.js:6465
IndexedDB (async)
(anonymous) @ auth.esm.js:6481
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
(anonymous) @ auth.esm.js:5177
(anonymous) @ auth.esm.js:5101
Dd @ auth.esm.js:2082
push../node_modules/@firebase/auth/dist/auth.esm.js.H.dispatchEvent @ auth.esm.js:2034
li @ auth.esm.js:4704
push../node_modules/@firebase/auth/dist/auth.esm.js.k.Jc @ auth.esm.js:4659
push../node_modules/@firebase/auth/dist/auth.esm.js.k.Vb @ auth.esm.js:4655
XMLHttpRequest.send (async)
ei @ auth.esm.js:4613
push../node_modules/@firebase/auth/dist/auth.esm.js.Ii.u @ auth.esm.js:5112
Si @ auth.esm.js:5077
(anonymous) @ auth.esm.js:5176
D @ auth.esm.js:1399
Yi @ auth.esm.js:5175
(anonymous) @ auth.esm.js:5662
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
(anonymous) @ auth.esm.js:5162
(anonymous) @ auth.esm.js:5101
Dd @ auth.esm.js:2082
push../node_modules/@firebase/auth/dist/auth.esm.js.H.dispatchEvent @ auth.esm.js:2034
li @ auth.esm.js:4704
push../node_modules/@firebase/auth/dist/auth.esm.js.k.Jc @ auth.esm.js:4659
push../node_modules/@firebase/auth/dist/auth.esm.js.k.Vb @ auth.esm.js:4655
XMLHttpRequest.send (async)
ei @ auth.esm.js:4613
push../node_modules/@firebase/auth/dist/auth.esm.js.Ii.u @ auth.esm.js:5112
Si @ auth.esm.js:5077
(anonymous) @ auth.esm.js:5161
D @ auth.esm.js:1399
Wi @ auth.esm.js:5160
Em @ auth.esm.js:8060
push../node_modules/@firebase/auth/dist/auth.esm.js.Am.getToken @ auth.esm.js:8076
(anonymous) @ auth.esm.js:8345
e.g @ auth.esm.js:1548
Sc @ auth.esm.js:1644
Oc @ auth.esm.js:1635
push../node_modules/@firebase/auth/dist/auth.esm.js.k.gc @ auth.esm.js:1625
xc @ auth.esm.js:1379
Promise.then (async)
uc @ auth.esm.js:1365
tc @ auth.esm.js:1354
Pc @ auth.esm.js:1613
zc @ auth.esm.js:1579
(anonymous) @ auth.esm.js:1400
a.onsuccess @ auth.esm.js:6465
uj5u.com熱心網友回復:
FirebaseError: Missing or insufficient permissions.
此錯誤通常表明 Firestore 受其默認規則保護,該規則禁止任何讀取或寫入操作以保護您的資料庫免受他人不必要的訪問:
allow read, write: if false;
但是,在實際使用 Firestore 時,需要調整這些規則以使您的 App 可以訪問 Firestore。最基本的安全規則是只允許用戶訪問已在您的應用中注冊的 Firestore:
allow read, write: if request.auth != null;
在進一步開發您的應用程式時,您可能希望使用其他規則將某些檔案限制為某些用戶等。
Firestore 規則在這里有更詳細的解釋:
https://firebase.google.com/docs/firestore/security/get-started
https://firebase.google.com/docs/firestore/security/rules-structure
https://firebase.google.com/docs/firestore/security/rules-conditions
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/498232.html
