Skip to content

Return object response data after login - #10

Open
albanafmeti wants to merge 1 commit into
Fab1en:masterfrom
albanafmeti:patch-1
Open

albanafmeti wants to merge 1 commit into
Fab1en:masterfrom
albanafmeti:patch-1

Conversation

@albanafmeti

Copy link
Copy Markdown

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

Fab1en commented Oct 10, 2017

Copy link
Copy Markdown
Owner

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
Copy Markdown
Author

Check this out https://github.com/albanafmeti/rocket-chat

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