Skip to content

added call to logout endpoint #84

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

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Changes from all commits
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
1 change: 1 addition & 0 deletions lib/src/base/parse_constants.dart
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ const String keyLibraryName = 'Flutter Parse SDK';
// End Points
const String keyEndPointUserName = '/users/me';
const String keyEndPointLogin = '/login';
const String keyEndPointLogout = '/logout';
const String keyEndPointUsers = '/users';
const String keyEndPointVerificationEmail = '/verificationEmailRequest';
const String keyEndPointRequestPasswordReset = '/requestPasswordReset';
1 change: 1 addition & 0 deletions lib/src/enums/parse_enum_api_rq.dart
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ enum ParseApiRQ {
currentUser,
signUp,
login,
logout,
loginAnonymous,
verificationEmailRequest,
requestPasswordReset,
34 changes: 29 additions & 5 deletions lib/src/objects/parse_user.dart
Original file line number Diff line number Diff line change
@@ -200,11 +200,35 @@ class ParseUser extends ParseObject implements ParseCloneable {
}
}

/// Removes the current user from the session data
logout() {
_client.data.sessionId = null;
unpin(key: keyParseStoreUser);
setObjectData(null);
/// Sends a request to delete the sessions token from the
/// server. Will also delete the local user data unless
/// deleteLocalUserData is false.
logout({bool deleteLocalUserData = true}) async {
if (deleteLocalUserData) {
_client.data.sessionId = null;
unpin(key: keyParseStoreUser);
setObjectData(null);
}

try {
if (username == null) return null;

Uri tempUri = Uri.parse(_client.data.serverUrl);

Uri url = Uri(
scheme: tempUri.scheme,
host: tempUri.host,
path: "${tempUri.path}$keyEndPointLogout");

final response = await _client.post(
url,
);

return _handleResponse(
this, response, ParseApiRQ.logout, _debug, className);
} on Exception catch (e) {
return _handleException(e, ParseApiRQ.logout, _debug, className);
}
}

/// Sends a verification email to the users email address