Add login and fix cookie logic bug