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
returnnew \WP_Error( 'graphql-jwt-improper-capabilities', __( 'The JWT Auth secret for this user cannot be returned', 'wp-graphql-jwt-authentication' ) );
226
+
returnnull;
224
227
}
225
228
226
229
/**
@@ -232,7 +235,7 @@ public static function get_user_jwt_secret( $user_id ) {
232
235
* If there is no stored secret, or it's not a string
// If the token cannot be returned, throw an error.
84
-
if ( empty( $token ) || is_wp_error( $token ) ) {
95
+
if ( empty( $token ) ) {
85
96
thrownewUserError( __( 'The JWT token could not be returned', 'wp-graphql-jwt-authentication' ) );
86
97
}
87
98
99
+
if ( $tokeninstanceof \WP_Error ) {
100
+
thrownewUserError( $token->get_error_message() );
101
+
}
102
+
88
103
return ! empty( $token ) ? $token : null;
89
104
},
90
105
],
91
106
'jwtRefreshToken' => [
92
107
'type' => 'String',
93
108
'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' ),
// If the token cannot be returned, throw an error.
101
-
if ( empty( $token ) || is_wp_error( $token ) ) {
126
+
if ( empty( $token ) ) {
102
127
thrownewUserError( __( 'The JWT token could not be returned', 'wp-graphql-jwt-authentication' ) );
103
128
}
104
129
130
+
if ( $tokeninstanceof \WP_Error ) {
131
+
thrownewUserError( $token->get_error_message() );
132
+
}
133
+
105
134
return ! empty( $token ) ? $token : null;
106
135
},
107
136
],
108
137
'jwtUserSecret' => [
109
138
'type' => 'String',
110
139
'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' ),
111
140
'resolve' => function ( $user ) {
141
+
142
+
$user_id = 0;
143
+
144
+
if ( isset( $user->userId ) ) {
145
+
$user_id = $user->userId;
146
+
} elseif ( isset( $user->ID ) ) {
147
+
$user_id = $user->ID;
148
+
}
149
+
112
150
// Get the user's JWT Secret.
113
-
$secret = Auth::get_user_jwt_secret( $user->ID );
151
+
$secret = Auth::get_user_jwt_secret( $user_id );
114
152
115
153
// If the secret cannot be returned, throw an error.
116
-
if ( is_wp_error( $secret) ) {
117
-
thrownewUserError( __( 'The user secret could not be returned', 'wp-graphql-jwt-authentication') );
@@ -134,7 +172,7 @@ public static function register_jwt_fields_to( $type ) {
134
172
'type' => [ 'non_null' => 'Boolean' ],
135
173
'description' => __( 'Whether the JWT User secret has been revoked. If the secret has been revoked, auth tokens will not be issued until an admin, or user with proper capabilities re-issues a secret for the user.', 'wp-graphql-jwt-authentication' ),
0 commit comments