Skip to content
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

Adds Option to define if a cookie should be set on login. #85

Merged
merged 5 commits into from
Oct 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,23 @@ public static function is_refresh_token() {
*/
protected static function authenticate_user( $username, $password ) {

/**
* Try to authenticate the user with the passed credentials
*/
$user = wp_authenticate( sanitize_user( $username ), trim( $password ) );
if (defined( 'GRAPHQL_JWT_AUTH_SET_COOKIES' ) && ! empty( GRAPHQL_JWT_AUTH_SET_COOKIES ) && GRAPHQL_JWT_AUTH_SET_COOKIES) {
jasonbahl marked this conversation as resolved.
Show resolved Hide resolved
$credentials = [
'user_login' => sanitize_user( $username ),
'user_password' => trim( $password ),
'remember' => false,
];

/**
* Try to authenticate the user with the passed credentials, log him in and set cookies
*/
henrikwirth marked this conversation as resolved.
Show resolved Hide resolved
$user = wp_signon( $credentials, true );
} else {
/**
* Try to authenticate the user with the passed credentials
*/
henrikwirth marked this conversation as resolved.
Show resolved Hide resolved
$user = wp_authenticate( sanitize_user( $username ), trim( $password ) );
}

/**
* If the authentication fails return a error
Expand Down