merged login and main to solve user scope issue