Upon completion of the function, ensure that no value is transmitted in TypeScript

After the first return, I am encountering an issue where the user.uid value is missing:

const functions = require(`firebase-functions`);
exports.createNewUser = functions.auth.user().onCreate((user: { uid: string; }) => {

    const newUserWallet: UserWallet = new UserWallet(user.uid);
    const rootUserWallet = admin.database().ref(`/Users/UserWallet/${user.uid}`); 
    return rootUserWallet.set(newUserWallet).then(() => {
        const newUserSettings: UserSettings = new UserSettings(user.uid);
        const rootUserSettings = admin.database().ref(`/Users/UserSettings/${user.uid}`);   
        return rootUserSettings.set(newUserSettings);
    })
    })

I have tried sending the value like this: .then((user.uid) => { or this: .then(user.uid => {, but it results in an error:

Argument of type 'string' is not assignable to parameter of type '((value: void) => void | PromiseLike<void>) | null | undefined'.ts(2345)

How can I pass this value correctly? This concerns a Firebase Function triggered upon the user creation event using TypeScript.

Answer №1

Uncertain about your intention behind the { uid: string; } section. It doesn't seem to match the structure of the user object.

However, a more efficient approach would be assigning user.uid to a constant and then utilizing it within the function. For instance:

module.exports = functions.auth.user().onCreate(user => {
  const uid = user.uid;
  // Would it make sense to simplify 'user.uid' to just 'uid' throughout the code?
})

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

Encountered a JavaScript error when trying to trigger an alert using PHP

I've incorporated fusion maps into one of my applications. In a particular example, I need to transfer values from one map to another chart, However, I encountered an issue where if the data passed is numeric, the alert message displays correctly, b ...

What is the best way to include message body in CDATA using strophe?

I have a task to create messages in a specific format by using the following code: $msg({to: 'user', from: 'me', type: 'chat'}).c("body").t('some data'); This code generates the message structure as follows: <m ...

Cease animation if the page has already reached its destination

In my current setup, I am using a JavaScript code snippet to navigate users to the specific location of the information they click on in a side navigation menu. However, one issue that arises is if they first click on one item and then another quickly, t ...

The outcome has been announced, yet its worth goes unnoticed within the realm of Ionic 3

I am encountering an issue with the following code snippet: async register(user: User){ try { const result = await this.afAuth.auth.createUserWithEmailAndPassword(user.email, user.password); this.userRegister(); } catch { this.showAlert(); } } Aft ...

Showing a loading screen based on the current state

I am trying to implement a loading screen component for Firebase data operations like user registration or login. I have defined the necessary indicators using useState, but the loading screen does not appear when the operation is in progress. Here is my ...

Tips for saving and retrieving req.user using JsonwebToken

Looking for ways to store and retrieve req.user using JsonwebToken in my booking application built with Node. I need to fetch the user information who booked a product and display it on the admin portal. .then((user) => { const maxAge = 3 * 60 * ...

What are the steps to implement the GET method with GraphQL and AJAX?

I've been delving into the world of Django and GraphQL by following this insightful documentation: django and graphql However, I've hit a roadblock halfway through where we can start testing with the graphql view and craft our queries. Instead ...

Updating a multitude of values efficiently

When updating multiple fields using ajax, I retrieve a row from the database on my server, JSON encode the row, and send it as the xmlhttp.responseText. The format of the response text is as follows: {"JobCardNum":5063,"IssueTo":"MachineShop","Priority": ...

Using Vue to dynamically add a CSS class based on a specific condition

I am in the process of creating a custom image slider with vuex and I would like to assign a specific class to the navigation dots used for sliding through the images. When a dot is active, it should have a class called dotActive. I intend to use the activ ...

Using React to update an existing array of objects with a new array containing objects of the same type

My issue involves an array in a class's state, referred to as A. A is populated with objects of type B through the function f in the constructor. Subsequently, I create a new array of objects of type B called C using f and new data. Upon setting the s ...

Discover ad blocking using react

I am currently trying to detect the presence of AdBlock Plus in Firefox. While it doesn't have to be foolproof, I would like to at least disable the pre-installed ad blockers in browsers like Firefox and Chrome. After some research, it seems that a p ...

Having trouble pinpointing the source files that are loading .js in the <head> section of my Magento website

My console is showing me three 404 errors related to missing .js files in the head section of my website. Even though I don't actually need these files, I want to stop receiving the 404 errors as they are affecting my analytics and SEO. The files caus ...

Decoding the Language of HTTP Status Codes

Let's imagine a scenario where I create a file called api.js: const {somefunction} = require('../controllers/some-controller'); app.get('/data/', somefunction); In my some-controller.js: exports.somefunction = async (req, res,next ...

Storing the .NET Framework viewmodel in its own individual Javascript file

I have a question about structuring my design for SoC (Separation of Concerns). I currently have the following files: testController.cs testViewModel.cs testView.cshtml testScript.js Currently, I generate data in the controller, populate the testViewMod ...

issue with displaying content with useEffect hook

Displaying a list of coupons based on the selected category using useEffect and saga. const initialState = { is_loading: true, coupon_data: [], error_msg: '', } This is the initial state. is_loading is set to true by default so that ...

Issue with Braintree drop-in form: Nonce string generation problem

I've encountered a peculiar issue while trying to utilize the dropin form from Braintree. Successfully integrating the form into a view, here's how it looks: <form id="createTransactionForm" method="post" action="#&qu ...

Retrieving the passed argument variable and utilizing it as a key in a map

I've been working on a JavaScript project recently and I've encountered a situation where I believe my code could be significantly reduced - up to 50% - if I could access the passed arguments to a function and use them as keys. Since I'm sti ...

The redirection to the specified URL is not working as expected in Ajax

I'm currently struggling to figure out why my AJAX code is not working as expected, specifically with redirecting to the provided URL. I've attempted troubleshooting by adding an alert message within my PHP code to confirm if it's redirectin ...

Is there a way to remove a value from the search bar while updating the table at the same time?

Although I can successfully search the table based on the values in my search bar, I am having trouble with updating the state when deleting a value. To see my code in action, check out my sandbox here. ...

JavaScript is claiming that my class method is invalid, despite the fact that it is obviously a valid function

Implementing a genetic algorithm using node has been my latest challenge. After browsing through the existing questions on this topic, I couldn't find anything relevant to my issue. The problem arises when I attempt to call the determine_fitness metho ...