Vue: Issue with Firebase Authentication REST API triggers 400 Bad Request Error

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.

Answer №1

The issue has been successfully resolved after discovering that the cause was due to Firebase. It turns out that the user's sign-in password was below 6 characters in length.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Converting JSON formatting from Object to Array: A Comprehensive Guide

Encountering another issue with changing the JSON array output. Struggling to figure out why it's not rendering the other files. Providing a clearer explanation below: In my code snippet, when I use data[name] = {, each return name is rendered into ...

Encountering undefined JavaScript functions when called from HTML

I had most of these functions working perfectly, but after restarting my program, I'm now encountering issues with undefined functions in Chrome. I can't pinpoint the exact problem, and even though I've checked through Eclipse, I still can&a ...

Is adding ng-click in a template counterproductive to the concept of MV* architecture?

When working with AngularJS, you may come across instances where the ng-click handler is directly connected to an HTML element like <a> or <button>. Take for example the snippet below (borrowed from an Angular homepage sample), where the click ...

The system considers the resource as a script, yet it was transmitted with the MIME type of text

I am encountering an issue when trying to integrate AngularJS/JavaScript into my HTML document. Each time I try to load my index.html file, the following error message appears: Resource interpreted as Script but transferred with MIME type text/html: "http ...

Javascript editing enhancement for real-time changes

Are there any tools for in-place editing of Javascript code? I'm looking for something similar to Firebug, which is great for instant CSS editing and previewing but doesn't have the capability to edit JavaScript directly. Is there a tool or addon ...

A guide to organizing elements in Javascript to calculate the Cartesian product in Javascript

I encountered a situation where I have an object structured like this: [ {attributeGroupId:2, attributeId: 11, name: 'Diamond'}, {attributeGroupId:1, attributeId: 9, name: '916'}, {attributeGroupId:1, attributeId: 1, name ...

Having trouble confirming signature with Node.js Crypto library, specifically with key pairs

I have a concise nodejs code snippet where I attempt to sign a string and then verify it using node crypto along with key pairs generated through openssl. Despite trying various methods, the result consistently shows "false" indicating that the signature c ...

The Bootstrap carousel controls now add the carousel ID to the address bar instead of just moving to the next slide

I can't figure out why my carousel isn't working. The id of the carousel is showing up in the webpage's address, which usually happens when the 'bootstrap.js' file is missing, but I have included it. Can anyone help me troubleshoo ...

What is the reason for needing to refresh when submitting form data in a Node application with an HTTP POST

Code Snippet - Angular .state('studentInfo.newStudent', { url : '/new/student', templateUrl: 'students/new-student.html', controller : function($state, $http){ this.saveStudent = func ...

Leveraging promises to make Ajax calls without repeating code

Would it be possible to create an ajax function without duplicating it? Passing different parameters, which are locations to various files. Then utilizing the promise to combine them into a single object, possibly incorporating the spread operator. Is th ...

What is the best way to choose an Animatedmodal that can showcase various demos while using just one ID?

I am currently customizing my website and utilizing the AnimatedModal.js framework. I have successfully displayed content in one modal, but encountered difficulty when attempting to create multiple modals as they all share the same ID. My question is, how ...

Navigating through parent folder HTML files from child folder HTML files

Seeking guidance as I embark on a new project! Check out this link to see my skills in action: collegewebsite.zip Now for the query at hand. I am working on a project named Coffee Cafe for my tuition assignment. It involves utilizing CSS and HTML with J ...

What is the best way to trigger a function once all asynchronous calls within a loop have been completed?

The function addData is called asynchronously within a loop every time reader.onloadend is triggered. const uploadFiles = () => { console.log(acceptedFiles) setLoading(true) console.log(loading) let i = 0 let l = acceptedFiles.length ...

Filtering Quantity Based on Specific Attribute in ReactJs

I want to implement a quantity filter that can be based on color, size, or both. For instance, when I select the red color, it should display the total quantity of red items available. However, if I choose both the color red and size small, it should show ...

Leveraging JavaScript for Validating Radio Buttons

I've been following a tutorial guide on this specific website , but I'm encountering some difficulties despite following the exact steps outlined. Can someone provide guidance? Here is what I have done: <html> <script> fu ...

Using a for loop, how can the property value be set in another object?

One challenge that I am facing is setting object property values. The object in question looks like this: const newPlan = { name: '', description: '', number: '', monday: { breakfast: '', ...

Analyzing past UTC date times results in a peculiar shift in time zones

When I receive various times in UTC from a REST application, I encounter different results. Examples include 2999-01-30T23:00:00.000Z and 1699-12-30T23:00:00.000Z. To display these times on the front end, I use new Date(date) in JavaScript to convert the ...

Modifying the initialValues prop on a Formik Form does not reflect changes in the input values

Utilizing a Formik form with forward refs in the following manner Form.js import React from "react"; import FormikWithRef from "./FormikWithRef"; const Form = ({ formRef, children, initialValues, validationSchema, onSubmit }) ...

Is there a way to load information retrieved from an API into a dropdown menu in Laravel with the help of VueJS and axios?

After many attempts, I still can't seem to fetch my API data into a select list successfully. Everything seems to be retrieved properly, but when it comes to displaying them, nothing shows up. Could there be an issue with my code? Here's my rout ...

What is the most effective method to prevent the auto-complete drop-down from repeating the same value multiple times?

My search form utilizes AJAX to query the database for similar results as the user types, displaying them in a datalist. However, I encountered an issue where it would keep appending matches that had already been found. For example: User types: "d" Datali ...