NFT Market Dapp error: not approved or not an owrner

Hello everyone, everything good?

I'm in need of some help...

I'm developing this NFT dapp from this Video:

NFT Fullstack Market

and Github repository:

Github repos

This Dapp works perfectly, I can create erc721 token and sell it...
However I'm wanting to implement the possibility of selling the nft that were purchased.

I think to transfer nft back to the market to sell, you need to transfer the tokenId to the Marketplace contract..

But when I run the sell button I get an error that was not approved or I'm not an owrner.

This is the code I'm reproducing to try to sell nft that were bought

 async function SellNFT(nft) {
    const web3Modal = new Web3Modal()
    const connection = await web3Modal.connect()
    const provider = new ethers.providers.Web3Provider(connection)    
    const signer = provider.getSigner()
    /* next, create the item */
    let contract = new ethers.Contract(nftaddress, NFT.abi, signer)
    const price = ethers.utils.parseUnits(nft.price, 'ether')
    /* then list the item for sale on the marketplace */
    contract = new ethers.Contract(nftmarketaddress, Market.abi, signer)
    let listingPrice = await contract.getListingPrice()
    listingPrice = listingPrice.toString()

    const transaction = await contract.createMarketItem(nftaddress, nft.tokenId, price, { value: listingPrice })
    await transaction.wait()

How can I approve the transaction for the contract using erc721?

and how can i call on web3..

Any help would be very welcome.

Before you call createMarketItem, you need to call the function approve on the NFT contract. Something like nftContract.approve(nftmarketaddress, nft.tokenId).

This is required because the market needs permission to take ownership of the NFT in order to sell it.