Skip to content

Commit b08e06e

Browse files
authored
Merge pull request #85 from wp-graphql/feature/add-set-cookies-option
Adds Option to define if a cookie should be set on login.
2 parents cf86790 + e3692a9 commit b08e06e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Auth.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,19 @@ public static function is_refresh_token() {
370370
*/
371371
protected static function authenticate_user( $username, $password ) {
372372

373-
/**
374-
* Try to authenticate the user with the passed credentials
375-
*/
376-
$user = wp_authenticate( sanitize_user( $username ), trim( $password ) );
373+
if ( defined( 'GRAPHQL_JWT_AUTH_SET_COOKIES' ) && ! empty( GRAPHQL_JWT_AUTH_SET_COOKIES ) && GRAPHQL_JWT_AUTH_SET_COOKIES ) {
374+
$credentials = [
375+
'user_login' => sanitize_user( $username ),
376+
'user_password' => trim( $password ),
377+
'remember' => false,
378+
];
379+
380+
// Try to authenticate the user with the passed credentials, log him in and set cookies
381+
$user = wp_signon( $credentials, true );
382+
} else {
383+
// Try to authenticate the user with the passed credentials
384+
$user = wp_authenticate( sanitize_user( $username ), trim( $password ) );
385+
}
377386

378387
/**
379388
* If the authentication fails return a error

0 commit comments

Comments
 (0)