Here is the error message I am encountering:
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
Here is a segment of the Vue JavaScript code that I have implemented:
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');
}
The issue might be with the functionality of JSON.stringify in converting the object into a JSON string. Here is the resource I referred to while developing my code:
https://firebase.google.com/docs/reference/rest/auth
I would appreciate it if someone could point out where I may have made an error.