refactor set authentication cookie