Index: trunk/Vanilla/templates/vanilla+authentication+userpics/javascript.mtml
===================================================================
--- trunk/Vanilla/templates/vanilla+authentication+userpics/javascript.mtml (revision 910)
+++ trunk/Vanilla/templates/vanilla+authentication+userpics/javascript.mtml (revision 915)
@@ -7,5 +7,5 @@
 <$mt:var name="show_userpic" value="1"$>
 
-/* section *****************************************************************/
+/* Section *****************************************************************/
 
 // The cookie name to use for storing the blog-side comment session cookie.
@@ -16,4 +16,6 @@
 var is_preview;
 var user;
+
+/* Login Functions *****************************************************************/
 
 <mt:Ignore>
@@ -110,4 +112,32 @@
 }
 
+<mt:IfBlog>
+<mt:IfRegistrationAllowed>
+/***
+ * If request contains a '#_login' or '#_logout' hash, use this to
+ * also delete the blog-side user cookie, since we're coming back from
+ * a login, logout or edit profile operation.
+ */
+var clearCookie = ( window.location.hash && window.location.hash.match( /^#_log(in|out)/ ) ) ? true : false;
+if (clearCookie) {
+    // clear any logged in state
+    mtClearUser();
+    if (RegExp.$1 == 'in')
+        mtFetchUser();
+} else {
+    <mt:Ignore>
+    /***
+     * Uncondition this call to fetch the current user state (if available)
+     * from MT upon page load if no user cookie is already present.
+     * This is okay if you have a private install, such as an Intranet;
+     * not recommended for public web sites!
+     */
+    </mt:Ignore>
+    if ( is_preview && !user )
+        mtFetchUser();
+}
+</mt:IfRegistrationAllowed>
+</mt:IfBlog>
+
 <mt:Ignore>
 /***
