Home > Software engineering >  Stripe connect http function firebase
Stripe connect http function firebase

Time:09-27

I have created a cloud function with the following: I'm trying to make an app/platform where a user can sign up for an account using Stripe Connect. I have a database with Firestore and the backend is using firebase cloud functions and nodejs.

const functions = require('firebase-functions');
const express = require('express');
const stripe = require('stripe')('sk_test_51XXX');
const admin = require('firebase-admin');
admin.initializeApp();


exports.createStripeUser = functions.https.onRequest((req, res) => {

    var auth_code = stripe.oauth.token({
        grant_type: 'authorization_code',
        code: req.query.code,
});return res.send("Please close this page")

}
)

My problem is that I have an error where the req, res is. I don't know why there is an error, is the request wrong? What can I do so that I get no error and fix the problem? enter image description here

If I hover on req, I get this message

(parameter) req: any
Parameter 'req' implicitly has an 'any' type.ts(7006)

I am using typescript

CodePudding user response:

It seems you are using Typescript and req, res are implicitly of type any. You can import Request and Response from Express as shown below:

import { Request, Response } from "express"

export const createStripeUser = functions.https.onRequest((req: Request, res: Response) => {
 // ...
})

And yes, explicitly adding any like (req: any, res: any) will remove that error too but that isn't the best thing to do.

  • Related