created middleware function to check if user is logged in