Javascript: TypeError: Cannot read properties of undefined (reading ‘startsWith’)

The error shows something to do with router.push(url)

My Submit function looks like this:

 const Submit= async()=>{
        const url = await PaymentMethod({ ...form.getValues(), price})
        router.push(url)
         }

PaymentMethod looks like this:


export const PaymentMethod = async (body) => {
    try{
        await connect()
        const transformedItem=[
        {
            price_data:{
                currency:'usd',
                product_data:{
                    name: body.title
                },
                unit_amount: body.price * 100,
            },
            quantity:1,
        },
    ]

The problem has to do something with the NEXT_PUBLIC_FRONTEND_URL but I’m not sure. The NEXT_PUBLIC_FRONTEND_URL is defined correctly in the .env file.


 const session = await stripe.checkout.sessions.create({
        payment_method_types:['card'],
        line_items:transformedItem,
        mode:'payment',
        success_url:`${process.env.NEXT_PUBLIC_FRONTEND_URL}/success`,
        cancel_url: `${process.env.NEXT_PUBLIC_FRONTEND_URL}/cancel`,
    })


Any suggestions what I’m doing wrong? Thanks!`