After encountering an issue with the Firebase inbuilt password reset functionality, I created a Firebase function to handle OTP verification and password changes based on the correctness of the OTP. The function is designed to validate the OTP provided, check if it matches the stored OTP in Firestore, retrieve the corresponding user's email address, and then update the user's password. Below is the code snippet of the function:
exports.resetPassword = functions.https.onCall((data, context) => {
return new Promise((resolve, reject) => {
// Function logic here
})
})
Despite observing execution logs in the console, when trying to run the function, I encountered the following client-side error message:
Access to fetch at 'https://us-central1-project-name.cloudfunctions.net/functionName' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
and
{"code":"internal"}
I'm now seeking advice on resolving this CORS (Cross-Origin Resource Sharing) issue that seems to be causing problems with the API call.
Part 2 (unrelated inquiry)
In lines 11 and 12 of my function, I'm using
admin.auth().getUserByEmail(data.email).then(user => {
admin.auth().updateUser(user.uid, {password: data.password})
})
Could you please verify if this code snippet correctly handles updating user passwords?
To seek solutions for the CORS problem, I consulted this thread on Stack Overflow, but unfortunately, it lacked any actionable answers.