Reputation: 35
I am trying to write a Cloud Function that validates a user's email when a new user is added to the users
Firestore table. (See this documentation.) I have this TypeScript code:
exports.validateEmail = functions.firestore
.document('users/{userId}')
.onCreate(async (snapshot, context) => {
const email = snapshot.get('email');
console.log(email); // Correctly logs email
await validateEmail(email);
});
export const validateEmail = async (email: string) => {
console.log(`Validating email: ${email}.`); // Code doesn't get to this line
// more code
};
However, I am getting the error:
"Cannot read property 'eventType' of undefined"
There is a similar question here although it refers to 'match' of undefined and none of the proposed solutions worked/applied for me.
I set the Cloud Function up by running firebase init
in a new project directory, selecting my Firebase project, choosing Functions, opting to install dependencies with npm, and opting for TypeScript. Here are relevant parts of my package.json:
"engines": {
"node": "10"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.11.0",
},
"devDependencies": {
"firebase-functions-test": "^0.2.0",
"tslint": "^5.12.0",
"typescript": "^3.8.0"
}
And here is part of my tsconfig.json:
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
}
Does anyone know what is undefined here - i.e. what is eventType
a property of, and how can I fix it?
Upvotes: 1
Views: 944
Reputation: 317362
You are redefining the validateEmail
function. You should just give the utility function another name that doesn't conflict with name of the first exported Cloud Function.
Upvotes: 1