这是我得到的错误:
POST
scheme
https
host
identitytoolkit.googleapis.com
filename
/v1/accounts:signUp
key
AIzaSyAk1ueCLjDDWCNrt_23o5A4RCfeaYIlN6k
Address
74.125.24.95:443
Status
400
Bad Request
VersionHTTP/3
Transferred850 B (198 B size)
Referrer Policystrict-origin-when-cross-origin
Request PriorityHighest
access-control-allow-origin
http://localhost:8080
access-control-expose-headers
date,vary,vary,vary,content-encoding,server,content-length
alt-svc
h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
cache-control
no-cache, no-store, max-age=0, must-revalidate
content-encoding
gzip
content-length
129
content-type
application/json; charset=UTF-8
date
Mon, 24 Oct 2022 12:07:19 GMT
expires
Mon, 01 Jan 1990 00:00:00 GMT
pragma
no-cache
server
ESF
vary
Origin
vary
X-Origin
vary
Referer
x-content-type-options
nosniff
x-frame-options
SAMEORIGIN
x-xss-protection
0
Accept
*/*
Accept-Encoding
gzip, deflate, br
Accept-Language
en-US,en;q=0.5
Connection
keep-alive
Content-Length
79
Content-Type
text/plain;charset=UTF-8
Host
identitytoolkit.googleapis.com
Origin
http://localhost:8080
Referer
http://localhost:8080/
Sec-Fetch-Dest
empty
Sec-Fetch-Mode
cors
Sec-Fetch-Site
cross-site
TE
trailers
User-Agent
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0
这是我正在使用的Vue JavaScript代码的一部分:
async auth() {
let url =
'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key= AIzaSyAk1ueCLjDDWCNrt_23o5A4RCfeaYIlN6k';
if (this.mode=="signup") {
url =
'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key= AIzaSyAk1ueCLjDDWCNrt_23o5A4RCfeaYIlN6k';
}
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify({
email: localStorage.getItem('email'),
password: localStorage.getItem('password'),
returnSecureToken: true
})
});
const responseData = await response.json();
if (!response.ok) {
const error = new Error(
responseData.message || 'Failed to authenticate. Check your login data.'
);
console.log(error);
throw error;
}
localStorage.setItem('token', responseData.idToken);
localStorage.setItem('userId', responseData.localId);
this.$store.state.token = localStorage.getItem('token');
this.$store.state.userId = localStorage.getItem('userId');
}
stringify应该将对象转换为JSON字符串,但我不确定这是否是问题所在。我在以下网站的帮助下开发了我的代码:
https://firebase.google.com/docs/reference/rest/auth
有人能告诉我我哪里做错了吗?
1条答案
按热度按时间kse8i1jr1#
我已经解决了这个问题。这个问题仅仅是由Firebase引起的,用户的登录密码少于6个字符。