Fix bug with the auth middleware

This was calling 'next' before the getPermissions callback had
completed, so wasn't working in a consistent way.
Return from getPermissions call is there's an error

Without this the function will carry on executing even after an error
has been passed to the callback.