File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class Auth {
2323 public static function get_secret_key () {
2424
2525 // Use the defined secret key, if it exists
26- $ secret_key = defined ( 'GRAPHQL_JWT_AUTH_SECRET_KEY ' ) && ! empty ( GRAPHQL_JWT_AUTH_SECRET_KEY ) ? GRAPHQL_JWT_AUTH_SECRET_KEY : ' graphql-jwt-auth ' ;
26+ $ secret_key = defined ( 'GRAPHQL_JWT_AUTH_SECRET_KEY ' ) && ! empty ( GRAPHQL_JWT_AUTH_SECRET_KEY ) ? GRAPHQL_JWT_AUTH_SECRET_KEY : null ;
2727 return apply_filters ( 'graphql_jwt_auth_secret_key ' , $ secret_key );
2828
2929 }
Original file line number Diff line number Diff line change @@ -189,12 +189,20 @@ private static function init() {
189189 * response status to 403.
190190 */
191191 add_action ( 'init_graphql_request ' , function () {
192- $ token = Auth::validate_token ();
193- if ( is_wp_error ( $ token ) ) {
194- add_action ( 'graphql_before_resolve_field ' , function () use ( $ token ) {
195- throw new \Exception ( $ token ->get_error_code () . ' | ' . $ token ->get_error_message () );
196- }, 1 );
192+
193+ $ jwt_secret = Auth::get_secret_key ();
194+ if ( empty ( $ jwt_secret ) || 'graphql-jwt-auth ' === $ jwt_secret ) {
195+ throw new \Exception ( __ ( 'You must define the GraphQL JWT Auth secret to use the WPGraphQL JWT Authentication plugin. ' , 'graphql-jwt-auth ' ) );
196+ } else {
197+ $ token = Auth::validate_token ();
198+ if ( is_wp_error ( $ token ) ) {
199+ add_action ( 'graphql_before_resolve_field ' , function () use ( $ token ) {
200+ throw new \Exception ( $ token ->get_error_code () . ' | ' . $ token ->get_error_message () );
201+ }, 1 );
202+ }
197203 }
204+
205+
198206 } );
199207
200208 }
You can’t perform that action at this time.
0 commit comments