Skip to content

Commit 3bbf50b

Browse files
committed
- More adjustments for the determine_current_user callback
1 parent e69b4b4 commit 3bbf50b

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

wp-graphql-jwt-authentication.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,8 @@ function init() {
198198

199199
add_action( 'plugins_loaded', '\WPGraphQL\JWT_Auth\init', 1 );
200200

201-
add_filter( 'determine_current_user', function( $user ) {
202201

203-
/**
204-
* Bail if it's not a GraphQL HTTP Request
205-
*
206-
* @todo: consider supporting REST too?
207-
*/
208-
if ( ! defined( 'GRAPHQL_HTTP_REQUEST' ) || false === GRAPHQL_HTTP_REQUEST ) {
209-
return $user;
210-
}
202+
add_filter( 'determine_current_user', function( $user ) {
211203

212204
/**
213205
* Validate the token, which will check the Headers to see if Authentication headers were sent
@@ -219,7 +211,7 @@ function init() {
219211
/**
220212
* If no token was generated, return the existing value for the $user
221213
*/
222-
if ( empty( $token ) ) {
214+
if ( empty( $token ) || is_wp_error( $token ) ) {
223215

224216
/**
225217
* Return the user that was passed in to the filter
@@ -239,9 +231,8 @@ function init() {
239231

240232
}
241233

242-
243234
/**
244235
* Everything is ok, return the user ID stored in the token
245236
*/
246237
return absint( $user );
247-
} );
238+
}, 99, 1 );

0 commit comments

Comments
 (0)