Skip to content

Commit 8732a8f

Browse files
author
Jeffrey
committed
Cleaner way to check for successful login
Snapchat returns ‘logged: true’ upon successful API call (in this case it means successful login) then we set the auth_token. Replacing the username with the username from Snapchat can be tricky as Snapchat will sometimes return ‘false’ so just leave that out.
1 parent 221e316 commit 8732a8f

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/snapchat.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,15 @@ public function login($username, $password) {
105105
)
106106
);
107107

108-
if (!empty($result)) {
109-
$this->cache = new SnapchatCache();
110-
$this->cache->set('updates', $result);
111-
}
112-
113-
// If the server sends back an auth token, remember it.
114-
if (!empty($result->auth_token)) {
108+
// If 'logged' is true (aka successful login), set the auth_token
109+
if ($result->logged) {
115110
$this->auth_token = $result->auth_token;
116111
}
117112

118-
// Store the logged in user.
119-
if (!empty($result->username)) {
120-
$this->username = $result->username;
113+
// Set cache
114+
if (!empty($result)) {
115+
$this->cache = new SnapchatCache();
116+
$this->cache->set('updates', $result);
121117
}
122118

123119
return $result;

0 commit comments

Comments
 (0)