Actually, just doing this check fixed this issue.
if(!is_user_logged_in())
{
wp_set_current_user($userid);
if(wp_validate_auth_cookie()==FALSE)
{
wp_set_auth_cookie($userid, true, false);
}
}
seems to have fixed this issue.
@here,your proposed solution didn’t work for me and just redirected me to login page when trying to get into dashboard