Skip to content

fix: JWT Auth hooks now support WPGraphQL Headless Login #812

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

Conversation

kidunot89
Copy link
Collaborator

Your checklist for this pull request

Thanks for sending a pull request! Please make sure you click the link above to view the contribution guidelines, then fill out the blanks below.

🚨Please review the guidelines for contributing to this repository.

  • Make sure you are making a pull request against the develop branch (left side). Also you should start your branch off our develop.
  • Make sure you are requesting to pull request from a topic/feature/bugfix/devops branch (right side). Don't pull request from your master!
  • Have you ensured/updated that CLI tests to extend coverage to any new logic. Learn how to modify the tests here.

What does this implement/fix? Explain your changes.

Updates the filters in WPGraphQL\WooCommerce\JWT_Auth_Schema_Filters to work with WPGraphQL Headless Login

Does this close any currently open issues?

Any relevant logs, error output, GraphiQL screenshots, etc?

(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)

Any other comments?

Where has this been tested?

  • WooGraphQL Version:
  • WPGraphQL Version:
  • WordPress Version:
  • WooCommerce Version:

@kidunot89 kidunot89 requested a review from justlevine October 15, 2023 15:55
@kidunot89 kidunot89 self-assigned this Oct 15, 2023
@kidunot89 kidunot89 added enhancement New feature or request bugfix Implements bugfix labels Oct 15, 2023
Comment on lines 25 to 31
if ( class_exists( '\WPGraphQL\JWT_Authentication\Auth' ) ) {
return '\WPGraphQL\JWT_Authentication\Auth';
} elseif ( class_exists( \WPGraphQL\Login\Main::class ) ) {
return \WPGraphQL\Login\Auth\TokenManager::class;
} else {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. class_exists() doesn't use a \ prefix.
  2. using the string instead of ::class for the check, so it doesn't error if the class doesnt exist.
  3. Checking for the class that's actually used instead of the parent class.
  4. Early return to reduce the code complexity.
     
Suggested change
if ( class_exists( '\WPGraphQL\JWT_Authentication\Auth' ) ) {
return '\WPGraphQL\JWT_Authentication\Auth';
} elseif ( class_exists( \WPGraphQL\Login\Main::class ) ) {
return \WPGraphQL\Login\Auth\TokenManager::class;
} else {
return null;
}
if ( class_exists( 'WPGraphQL\JWT_Authentication\Auth' ) ) {
return \WPGraphQL\JWT_Authentication\Auth::class;
}
if ( class_exists( 'WPGraphQL\Login\Auth\TokenManager' ) ) {
return \WPGraphQL\Login\Auth\TokenManager::class;
}
return null;

*
* @var \WP_Error|string|null $token
*/
$token = $auth_class::get_token( $user );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's WPGraphQL\Login\Auth\TokenManager::get_auth_token().

Can probably use a method_exists( $auth_class, ...) to call the correct method.

@kidunot89 kidunot89 merged commit 3cf05bd into wp-graphql:develop Oct 16, 2023
@kidunot89 kidunot89 deleted the feat/wp-graphql-headless-login-integration-fix branch October 16, 2023 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Implements bugfix enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants