Both are correct but can mean a different thing. Rule of thumb: the nicht is placed in front of the thing negated, which also gets the focus because of that:
Warum dürfen wir den Apfelkuchen nicht essen? – Weil er noch heiß ist.
Warum dürfen wir nicht den Apfelkuchen essen? – Weil ihr erstmal euer Gemüse essen sollt.
Warum dürfen nicht wir den Apfelkuchen essen? – Weil der für Omas Kaffeekränzchen ist.
These examples are a bit constructed because the question already asks for the right thing, but I think you get the difference in meaning.