You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#41 - JWT fields cannot be retrieved via viewer query
- When the Model Layer was introduced it changed the objects that are passed down to fields on the Viewer. This adjusts the field resolvers to expect a User (model) instead of WP_User to be passed down
Copy file name to clipboardExpand all lines: src/ManageTokens.php
+11-6Lines changed: 11 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
namespaceWPGraphQL\JWT_Authentication;
4
4
5
5
useGraphQL\Error\UserError;
6
+
useWPGraphQL\Model\User;
6
7
useWPGraphQL\Types;
7
8
8
9
class ManageTokens {
@@ -85,7 +86,9 @@ public static function add_user_fields( $fields ) {
85
86
$fields['jwtAuthToken'] = [
86
87
'type' => Types::string(),
87
88
'description' => __( 'A JWT token that can be used in future requests for authentication/authorization', 'wp-graphql-jwt-authentication' ),
88
-
'resolve' => function ( \WP_User$user ) {
89
+
'resolve' => function ( User$user ) {
90
+
91
+
$user = get_user_by( 'id', $user->userId );
89
92
90
93
/**
91
94
* Get the token for the user
@@ -106,7 +109,9 @@ public static function add_user_fields( $fields ) {
106
109
$fields['jwtRefreshToken'] = [
107
110
'type' => Types::string(),
108
111
'description' => __( 'A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.', 'wp-graphql-jwt-authentication' ),
109
-
'resolve' => function ( \WP_User$user ) {
112
+
'resolve' => function ( User$user ) {
113
+
114
+
$user = get_user_by( 'id', $user->userId );
110
115
111
116
/**
112
117
* Get the token for the user
@@ -127,12 +132,12 @@ public static function add_user_fields( $fields ) {
127
132
$fields['jwtUserSecret'] = [
128
133
'type' => Types::string(),
129
134
'description' => __( 'A unique secret tied to the users JWT token that can be revoked or refreshed. Revoking the secret prevents JWT tokens from being issued to the user. Refreshing the token invalidates previously issued tokens, but allows new tokens to be issued.', 'wp-graphql' ),
0 commit comments