Refactor authentication function
Add sessions specs