|
1 | 1 | <?php |
2 | | -/** |
3 | | - * Register the login mutation to the WPGraphQL Schema |
4 | | - * |
5 | | - * @package WPGraphQL\JWT_Authentication |
6 | | - * @since 0.0.1 |
7 | | - */ |
8 | | - |
9 | 2 | namespace WPGraphQL\JWT_Authentication; |
10 | 3 |
|
11 | 4 | use GraphQL\Type\Definition\ResolveInfo; |
12 | 5 | use WPGraphQL\AppContext; |
13 | 6 |
|
14 | | -/** |
15 | | - * Class - Login |
16 | | - */ |
17 | 7 | class Login { |
| 8 | + |
18 | 9 | /** |
19 | | - * Register the mutation. |
| 10 | + * Register the login mutation to the WPGraphQL Schema |
20 | 11 | */ |
21 | 12 | public static function register_mutation() { |
22 | | - register_graphql_mutation( |
23 | | - 'login', |
24 | | - [ |
25 | | - 'description' => __( 'Login a user. Request for an authToken and User details in response', 'wp-graphql-jwt-authentication' ), |
26 | | - 'inputFields' => [ |
27 | | - 'username' => [ |
28 | | - 'type' => [ 'non_null' => 'String' ], |
29 | | - 'description' => __( 'The username used for login. Typically a unique or email address depending on specific configuration', 'wp-graphql-jwt-authentication' ), |
30 | | - ], |
31 | | - 'password' => [ |
32 | | - 'type' => [ 'non_null' => 'String' ], |
33 | | - 'description' => __( 'The plain-text password for the user logging in.', 'wp-graphql-jwt-authentication' ), |
34 | | - ], |
| 13 | + |
| 14 | + register_graphql_mutation( 'login', [ |
| 15 | + 'description' => __( 'Login a user. Request for an authToken and User details in response', 'wp-graphql-jwt-authentication' ), |
| 16 | + 'inputFields' => [ |
| 17 | + 'username' => [ |
| 18 | + 'type' => [ 'non_null' => 'String' ], |
| 19 | + 'description' => __( 'The username used for login. Typically a unique or email address depending on specific configuration', 'wp-graphql-jwt-authentication' ), |
| 20 | + ], |
| 21 | + 'password' => [ |
| 22 | + 'type' => [ 'non_null' => 'String' ], |
| 23 | + 'description' => __( 'The plain-text password for the user logging in.', 'wp-graphql-jwt-authentication' ), |
| 24 | + ], |
| 25 | + ], |
| 26 | + 'outputFields' => [ |
| 27 | + 'authToken' => [ |
| 28 | + 'type' => 'String', |
| 29 | + 'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-jwt-authentication' ), |
35 | 30 | ], |
36 | | - 'outputFields' => [ |
37 | | - 'authToken' => [ |
38 | | - 'type' => 'String', |
39 | | - 'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-jwt-authentication' ), |
40 | | - ], |
41 | | - 'refreshToken' => [ |
42 | | - 'type' => 'String', |
43 | | - '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' ), |
44 | | - ], |
45 | | - 'user' => [ |
46 | | - 'type' => 'User', |
47 | | - 'description' => __( 'The user that was logged in', 'wp-graphql-jwt-authentication' ), |
48 | | - ], |
| 31 | + 'refreshToken' => [ |
| 32 | + 'type' => 'String', |
| 33 | + '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' ), |
49 | 34 | ], |
50 | | - 'mutateAndGetPayload' => function( $input, AppContext $context, ResolveInfo $info ) { |
51 | | - // Login the user in and get an authToken and user in response. |
52 | | - return Auth::login_and_get_token( sanitize_user( $input['username'] ), trim( $input['password'] ) ); |
53 | | - }, |
54 | | - ] |
55 | | - ); |
| 35 | + 'user' => [ |
| 36 | + 'type' => 'User', |
| 37 | + 'description' => __( 'The user that was logged in', 'wp-graphql-jwt-authentication' ), |
| 38 | + ], |
| 39 | + ], |
| 40 | + 'mutateAndGetPayload' => function( $input, AppContext $context, ResolveInfo $info ) { |
| 41 | + |
| 42 | + /** |
| 43 | + * Login the user in and get an authToken and user in response |
| 44 | + */ |
| 45 | + return Auth::login_and_get_token( sanitize_user( $input['username'] ), trim( $input['password'] ) ); |
| 46 | + |
| 47 | + }, |
| 48 | + ]); |
| 49 | + |
56 | 50 | } |
| 51 | + |
57 | 52 | } |
0 commit comments