Trying to create user programmatically, running into issues I'm attempting to programmatically create a user. I'd like to be able to create the user, then set the current global $user object to this newly created user. Here is what my code looks like.

    $new_user = array(
        'name' =&gt; $form_state['values']['username'],
        'pass' =&gt; $form_state['values']['password'],
        'mail' =&gt; $form_state['values']['email'],
        'status' =&gt; 1,
        'init' =&gt; $form_state['values']['email'],
        'roles' =&gt; array(
            DRUPAL_AUTHENTICATED_RID =&gt; 'authenticated user'
        )
    );

    if ($saved_user = user_save(NULL, $new_user)){
        user_load($saved_user-&gt;uid, TRUE);
        $form_state['redirect'] = 'member/profile';
    } else {
        $form_state['redirect'] = 'member/join';
    }


The reason for me essentially wrapping the existing user page is that there is a lot of additional functionality needed. This code does create a user in the database, but it fails in two places: 1) It does not create any roles for this new user in the users_roles table, and 2) It does not log the current user in or adjust the global $user object.

Any ideas why this is failing?

EDIT: Using Drupal 7.9

EDIT2: I solved the user not being logged in issue by using the function user_login_submit. Roles still aren't creating correctly, however.
Drupal's anonymous and authenticated roles don't get saved in the users_roles table and you don't need to add the role yourself, all users are by default authenticated. Try editing your user in the backend, you'll see that it has authenticated checked off.
The code you list above where you send the roles array in the $edit will work fine with any other role.