Skip to content

Commit 97e5556

Browse files
committed
Adds Option to define if a cookie should be set on login.
1 parent e65055d commit 97e5556

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/Auth.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,23 @@ public static function is_refresh_token() {
355355
*/
356356
protected static function authenticate_user( $username, $password ) {
357357

358-
/**
359-
* Try to authenticate the user with the passed credentials
360-
*/
361-
$user = wp_authenticate( sanitize_user( $username ), trim( $password ) );
358+
if (defined( 'GRAPHQL_JWT_AUTH_SET_COOKIES' ) && ! empty( GRAPHQL_JWT_AUTH_SET_COOKIES ) && GRAPHQL_JWT_AUTH_SET_COOKIES) {
359+
$credentials = [
360+
'user_login' => sanitize_user( $username ),
361+
'user_password' => trim( $password ),
362+
'remember' => false,
363+
];
364+
365+
/**
366+
* Try to authenticate the user with the passed credentials, log him in and set cookies
367+
*/
368+
$user = wp_signon( $credentials, true );
369+
} else {
370+
/**
371+
* Try to authenticate the user with the passed credentials
372+
*/
373+
$user = wp_authenticate( sanitize_user( $username ), trim( $password ) );
374+
}
362375

363376
/**
364377
* If the authentication fails return a error

0 commit comments

Comments
 (0)