You need to get familiar with melodic tension and resolution. There is a huge line between writing riffs and making a cohesive song that flows...which is why it takes me months to write one...MONTHS.
It also doesn't help that it has to be perfect to my ears. Like no hint of being contrived, familiar or a novelty. Everything I write is painfully picked out and every melodic possibility is explored.
My writers block always comes when I back myself into a corner and the only resolution that fits leaves me feeling a lack of contentment. Then frustration sets in because I have to go back and rewrite the previous phrase to lead elsewhere.
What helps me is audibly visualizing the song. I play the passage in my head and imagine myself playing it with a full band. What do you hear come after the riff and where is it heading? If you can play what you hear in you're head, congratulations, you have made great progress!