Skip to content

Initial loginWith #94

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 2 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
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/enums/parse_enum_api_rq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum ParseApiRQ {
login,
logout,
loginAnonymous,
loginWith,
verificationEmailRequest,
requestPasswordReset,
destroy,
Expand Down
40 changes: 39 additions & 1 deletion lib/src/objects/parse_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ParseUser extends ParseObject implements ParseCloneable {

ParseUser.forQuery() : super(keyClassUser);

createUser(String username, String password, [String emailAddress]) {
static createUser([String username, String password, String emailAddress]) {
return ParseUser(username, password, emailAddress);
}

Expand Down Expand Up @@ -206,6 +206,44 @@ class ParseUser extends ParseObject implements ParseCloneable {
}
}

// Logs in a user using a service
static Future<ParseUser> loginWith(String provider, Object authData) async {
ParseUser user = ParseUser.createUser();
var response = await user._loginWith(provider, authData);
if (response.success) {
return user;
} else {
return Future.error(response);
}
}

Future<ParseResponse> _loginWith(String provider, Object authData) async {
try {
Uri tempUri = Uri.parse(_client.data.serverUrl);

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

final response = await _client.post(url,
headers: {
keyHeaderRevocableSession: "1",
},
body: jsonEncode({
"authData": {
provider: authData
}
}));

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

/// Sends a request to delete the sessions token from the
/// server. Will also delete the local user data unless
/// deleteLocalUserData is false.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
http: ^0.12.0

# Utils
shared_preferences: ^0.4.3
shared_preferences: ^0.5.0
path_provider: ^0.4.1
uuid: ^1.0.3

Expand Down