File tree Expand file tree Collapse file tree 2 files changed +10
-41
lines changed Expand file tree Collapse file tree 2 files changed +10
-41
lines changed Original file line number Diff line number Diff line change @@ -378,7 +378,7 @@ public static function filter_determine_current_user( $user ) {
378378 /**
379379 * If no token was generated, return the existing value for the $user
380380 */
381- if ( empty ( $ token ) ) {
381+ if ( empty ( $ token ) || is_wp_error ( $ token ) ) {
382382
383383 /**
384384 * Return the user that was passed in to the filter
@@ -398,7 +398,6 @@ public static function filter_determine_current_user( $user ) {
398398
399399 }
400400
401-
402401 /**
403402 * Everything is ok, return the user ID stored in the token
404403 */
@@ -489,6 +488,7 @@ public static function unrevoke_user_secret( int $user_id ) {
489488
490489 }
491490
491+
492492 protected static function set_status ( $ status_code ) {
493493 add_filter ( 'graphql_response_status_code ' , function () use ( $ status_code ) {
494494 return $ status_code ;
Original file line number Diff line number Diff line change @@ -171,6 +171,14 @@ private static function init() {
171171 */
172172 ManageTokens::init ();
173173
174+ /**
175+ * Filter how WordPress determines the current user
176+ */
177+ add_filter ( 'determine_current_user ' , [
178+ '\WPGraphQL\JWT_Authentication\Auth ' ,
179+ 'filter_determine_current_user '
180+ ], 99 , 1 );
181+
174182 /**
175183 * Filter the rootMutation fields
176184 */
@@ -197,42 +205,3 @@ function init() {
197205}
198206
199207add_action ( 'plugins_loaded ' , '\WPGraphQL\JWT_Auth\init ' , 1 );
200-
201-
202- add_filter ( 'determine_current_user ' , function ( $ user ) {
203-
204- /**
205- * Validate the token, which will check the Headers to see if Authentication headers were sent
206- *
207- * @since 0.0.1
208- */
209- $ token = Auth::validate_token ();
210-
211- /**
212- * If no token was generated, return the existing value for the $user
213- */
214- if ( empty ( $ token ) || is_wp_error ( $ token ) ) {
215-
216- /**
217- * Return the user that was passed in to the filter
218- */
219- return $ user ;
220-
221- /**
222- * If there is a token
223- */
224- } else {
225-
226- /**
227- * Get the current user from the token
228- */
229- $ user = ! empty ( $ token ) && ! empty ( $ token ->data ->user ->id ) ? $ token ->data ->user ->id : $ user ;
230-
231-
232- }
233-
234- /**
235- * Everything is ok, return the user ID stored in the token
236- */
237- return absint ( $ user );
238- }, 99 , 1 );
You can’t perform that action at this time.
0 commit comments