Skip to content

Log in with token #58

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

Closed
pcg92 opened this issue Jan 27, 2019 · 3 comments
Closed

Log in with token #58

pcg92 opened this issue Jan 27, 2019 · 3 comments

Comments

@pcg92
Copy link
Contributor

pcg92 commented Jan 27, 2019

Hey, I need to login the user from a token. What do you think about this code? I can do a PR if its ok.

  Future<ParseResponse> getCurrentUserFromServer({token}) async {
    // We can't get the current user and session without a sessionId

    if(token==null && _client.data.sessionId == null) {
      return null;
    }

    if(token == null){
      token = _client.data.sessionId;
    }

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

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

      final response = await _client.get(uri, headers: {keyHeaderSessionToken: token});
      return _handleResponse(response, ParseApiRQ.currentUser);
    } on Exception catch (e) {
      return _handleException(e, ParseApiRQ.currentUser);
    }
  }

With this changes, I can do the following:

  initUserFromToken () async{
    ParseUser user = new ParseUser(null,null,null);
    var response = await user.getCurrentUserFromServer(token:"r:78095e44937ff1732f18ea04d04ad67e");
    if (response.success){
      user = await ParseUser.currentUser();
      print("user"+user.get(ParseUser.keyUsername));
    }
  }
@phillwiggins
Copy link
Member

phillwiggins commented Jan 27, 2019 via email

@pcg92
Copy link
Contributor Author

pcg92 commented Jan 27, 2019

Yes its tested, the function initUser() in main its working like a charm, and the snippet that I included here its working too.

@phillwiggins
Copy link
Member

phillwiggins commented Jan 27, 2019 via email

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

No branches or pull requests

2 participants