Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using jwt_auth_token_before_sign creates invalid json #292

Open
4 of 5 tasks
simonh1000 opened this issue Nov 5, 2023 · 0 comments
Open
4 of 5 tasks

using jwt_auth_token_before_sign creates invalid json #292

simonh1000 opened this issue Nov 5, 2023 · 0 comments

Comments

@simonh1000
Copy link

simonh1000 commented Nov 5, 2023

Issue Name

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest plugin version
  • I am running the latest WordPress version
  • I know what PHP version I'm using
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • WordPress version 6.x
  • PHP Version
  • 1.3.4

Expected Behavior

I'm not a PHP specialist, so i'm just trying to extend code I fond on stackoverflow

I have

add_action( 'jwt_auth_token_before_sign', 'jwt_token', 10, 2 );

function jwt_token($token, $user) {
  $data = [
    'user' => [
        'id' => $user->data->ID,
        'name' => $user->data->display_name,
        'roles' => implode(',', $user->roles)
    ]
  ];
  $token['data'] = $data;
  return $token;
}

the trouble is that when this returns after an auth request I get

Array{
    "token": "eyJ0e...NcbMJcQ",
    "user_email": "[email protected]",
    "user_nicename": "xyz",
    "user_display_name": "xyz"
}

the word Array is then messing up the parsing in the client

Any ideas how to return a $token that continues to json encode properly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant