Did you override CUserIdentity::getId() ? I guess $identity doesn't have a valid ID value even if you call authenticate() (because your password may not be correct since it may be encoded.)
I'm using the webapp generated UserIdentity, which has getId overridden:
It's just strange that I can log them in manually since the password is the same from the form or from the DB (same salt and hashing).
When I echo Yii::app()->user->id outside of the conditional after auto login authentication, it's empty, but when I log in manually, the id shows up, so you're right, it's not getting the id, I just can't figure out why since the very same functions are being called in both cases.
It's the same and only UserIdentity class in the app.
All you need is a valid user ID. So you may add a new method in your UserIdentity class which will find the ID based on the given username. You can call this method and then login the identity.