{"id":13556479,"date":"2020-10-20T09:39:12","date_gmt":"2020-10-20T09:39:12","guid":{"rendered":"https:\/\/wordpress.org\/support\/?post_type=topic&#038;p=13556479"},"modified":"2020-10-20T09:46:44","modified_gmt":"2020-10-20T09:46:44","slug":"token-null-on-modified-response","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/token-null-on-modified-response\/","title":{"rendered":"Token null on modified response"},"content":{"rendered":"<p>I tried to modify &#8220;JWT_AUTH_VALID_CREDENTIAL_RESPONSE&#8221; like shown in the docs.<\/p>\n<p>But as soon as I do this (using a simple plugin for this) the token is null (although the reponse still says success:true).<\/p>\n<p>Even with no changes to the reponse function that happens.<\/p>\n<pre><code>\n\/**\n * Modify the response of valid credential.\n *\n * @param array $response The default valid credential response.\n * @param WP_User $user The authenticated user.\n * .\n * @return array The valid credential response.\n *\/\nadd_filter(\n    &#039;jwt_auth_valid_credential_response&#039;,\n    function ( $response, $user ) {\n $response = array(\n    &#039;success&#039;    =&gt; true,\n    &#039;statusCode&#039; =&gt; 200,\n    &#039;code&#039;       =&gt; &#039;jwt_auth_valid_credential&#039;,\n    &#039;message&#039;    =&gt; __( &#039;Credential is valid&#039;, &#039;jwt-auth&#039; ),\n    &#039;data&#039;       =&gt; array(\n        &#039;token&#039;       =&gt; $token,\n        &#039;id&#039;          =&gt; $user-&gt;ID,\n        &#039;email&#039;       =&gt; $user-&gt;user_email,\n        &#039;nicename&#039;    =&gt; $user-&gt;user_nicename,\n        &#039;firstName&#039;   =&gt; $user-&gt;first_name,\n        &#039;lastName&#039;    =&gt; $user-&gt;last_name,\n        &#039;displayName&#039; =&gt; $user-&gt;display_name,\n    ),\n);\n        return $response;\n    },\n    10,\n    2\n);\n<\/code><\/pre>\n<p>Then I tried to modify the &#8220;JWT_AUTH_VALID_TOKEN_RESPONSE&#8221;, which works fine.<\/p>\n<p>Any idea what&#8217;s wrong with the modified &#8220;JWT_AUTH_VALID_CREDENTIAL_RESPONSE&#8221;?<\/p>\n","protected":false},"template":"","class_list":["post-13556479","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13556479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":2,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13556479\/revisions"}],"predecessor-version":[{"id":13556524,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13556479\/revisions\/13556524"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13556479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}