I want to have a short code to show the last 2 posts posted by the user connected in a sidebar widget or anywhere

I have read several responses about displaying posts created by the currently logged in user. However, I still can't create a short code that I can use in a widget or page to display the last 2 posts created by the current user, for example, this one.

 get_current_user_id(),
));

while ( $query->have_posts() ) {
    $query->the_post();
    the_title();
}
    wp_reset_postdata();
?>