fix: Clear auth cookies before setting new ones + trigger wp_login action

This commit is contained in:
dwindown
2025-11-05 10:02:40 +07:00
parent ff29f95264
commit 7c24602965

View File

@@ -49,10 +49,14 @@ class AuthController {
], 403 );
}
// CRITICAL: Set auth cookie AND current user (as per WordPress best practices)
// This ensures session is properly established for both standalone and wp-admin
wp_set_auth_cookie( $user->ID, true, is_ssl() );
// CRITICAL: Clear old cookies first, then set new ones
// This ensures no stale session data interferes with the new login
wp_clear_auth_cookie();
wp_set_current_user( $user->ID );
wp_set_auth_cookie( $user->ID, true );
// Trigger login action (same as wp-login.php)
do_action( 'wp_login', $user->user_login, $user );
// Debug logging
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {