paul seems
paul seems

Reputation: 565

Doing something after "redirect" in Cloud Function?

I would like to write to DB after i redirect a user:

 exports.contentServer = functions.https.onRequest((request, response) => {
...
...
    return response.redirect(finalUrl + "front?action=" + action ) 
 
     .then(function(){   //  **** error : .then of undefined
        ....

I get an error in the promise.

Cannot read property 'then' of undefined
    at exports.contentServer.functions.https.onRequest
           

Upvotes: 0

Views: 376

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

As far as I can tell redirect doesn't return a Promise. In fact, from the undefined in your error message it seems like it doesn't return anything at all. The documentation also doesn't show any return value: https://expressjs.com/en/api.html#res.redirect

If it were to return something, you could capture that value and return it later:

const result = response.redirect(finalUrl + "front?action=" + action ) 

....

return result;

Upvotes: 1

Related Questions