In Spain, marijuana can be legally consumed in private spaces, such as at home or in private clubs. Public consumption is illegal and can result in heavy fines. One option is to join Cannabis Social Clubs, which you can find here
https://barcelonaweedmap.com/ , they are private associations where cannabis can be consumed legally. These clubs require membership, which usually includes a referral and an annual fee. Always remember that while personal use in private is allowed, carrying cannabis in public can lead to legal problems.