Add some error checking into authentication