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

Return object response data after login #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Return object response data after login #10

wants to merge 1 commit into from

Conversation

albanafmeti
Copy link

Why returning true when somebody may need more information for example authToken ?
The returned object is different from false so I think it will be fine returning the object $response->body->data.

Why returning `true` when somebody may need more information for example `authToken` ?
The returned object is different from `false` so I think it will be fine returning the object `$response->body->data`.
@Fab1en
Copy link
Owner

Fab1en commented Oct 10, 2017

Thanks for collaborating @albanafmeti !
I chose to encapsulate a maximum of the login logic inside the API objects, so that it's straightforward to use it. Concerning the Auth Token, I save it when the login method is called with $save_auth=true :

if( $save_auth) {
	// save auth token for future requests
	$tmp = Request::init()
		->addHeader('X-Auth-Token', $response->body->data->authToken)
		->addHeader('X-User-Id', $response->body->data->userId);
	Request::ini( $tmp );
}

Doing this will ship the auth token automatically with following requests, so you don't have to worry about it.

If you need the auth token outside the login method, you can get it from the Request :

$token = Request::init()->headers["X-Auth-Token"];

@albanafmeti
Copy link
Author

nelsonko added a commit to nelsonko/rocket-chat-rest-client that referenced this pull request Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants