Skip to content

Commit ef3bf48

Browse files
committed
- fix the viewer query not returning the authenticated user by instantiating the plugin at "plugins_loaded" so the "determine_current_user" filter would be applied, which occurs BEFORE "graphql_init" is fired, so the plugin was being instantiated too late.
1 parent 9ad7e46 commit ef3bf48

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/Auth.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,14 @@ public static function filter_determine_current_user( $user ) {
394394
*/
395395
$user = ! empty( $token ) && ! empty( $token->data->user->id ) ? $token->data->user->id : $user;
396396

397+
397398
}
398399

400+
399401
/**
400402
* Everything is ok, return the user ID stored in the token
401403
*/
402-
return $user;
404+
return absint( $user );
403405
}
404406

405407
/**

wp-graphql-jwt-authentication.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ private static function init() {
169169
*/
170170
ManageTokens::init();
171171

172+
/**
173+
* Filter how WordPress determines the current user
174+
*/
175+
add_filter( 'determine_current_user', [
176+
'\WPGraphQL\JWT_Authentication\Auth',
177+
'filter_determine_current_user'
178+
], 10, 1 );
179+
172180
/**
173181
* Filter the rootMutation fields
174182
*/
@@ -182,13 +190,7 @@ private static function init() {
182190
'root_mutation_fields'
183191
], 10, 1 );
184192

185-
/**
186-
* Filter how WordPress determines the current user
187-
*/
188-
add_filter( 'determine_current_user', [
189-
'\WPGraphQL\JWT_Authentication\Auth',
190-
'filter_determine_current_user'
191-
], 10 );
193+
192194

193195
}
194196

@@ -200,4 +202,4 @@ function init() {
200202
return JWT_Authentication::instance();
201203
}
202204

203-
add_action( 'graphql_init', '\WPGraphQL\JWT_Authentication\init' );
205+
add_action( 'plugins_loaded', '\WPGraphQL\JWT_Authentication\init' );

0 commit comments

Comments
 (0)