Skip to content

becomeInBackground #61

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
ghost opened this issue Jan 29, 2019 · 9 comments
Closed

becomeInBackground #61

ghost opened this issue Jan 29, 2019 · 9 comments

Comments

@ghost
Copy link

ghost commented Jan 29, 2019

Hi,

Is it possible to use becomeInBackground (like in the Android guide from Parse : https://docs.parseplatform.org/android/guide/#setting-the-current-user)

ParseUser.becomeInBackground("session-token-here", new LogInCallback() {
  public void done(ParseUser user, ParseException e) {
    if (user != null) {
      // The current user is now set to user.
    } else {
      // The token could not be validated.
    }
  }
});
@pcg92
Copy link
Contributor

pcg92 commented Jan 29, 2019

Yes, you need to send the token from a cloud function, and then you can do this:

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));
    }
  }

But this is not in release, so we need to wait to the new release, see #58

@ghost
Copy link
Author

ghost commented Jan 29, 2019

Oh ok and could you show me an exemple of how you retrieve the token from your cloud function response please ?

@pcg92
Copy link
Contributor

pcg92 commented Jan 29, 2019

Yes, this is not a cloud function, but you can do something like this, and return the token in the cloud function.

async function getTokenFromUser(user: Parse.User): Promise<string> {
    var randomPassword = generateRandomPw();
    user.setPassword(randomPassword);
    await user.save(null, {useMasterKey: true});
    user = await Parse.User.logIn(user.get("username"), randomPassword);
    return user.getSessionToken();
}

I dont know if this code will work for you, Im doing a login without password, its by email link/code.

@ghost
Copy link
Author

ghost commented Jan 29, 2019

The method 'getSessionToken' isn't defined for the classe 'ParseUser'.

Oh, I can't call .getSessionToken() on my user, where this method comes from ?

@pcg92
Copy link
Contributor

pcg92 commented Jan 29, 2019

Is a js method, in your cloud code you can call it:
https://parseplatform.org/Parse-SDK-JS/api/2.1.0/Parse.User.html#getSessionToken

@ghost
Copy link
Author

ghost commented Jan 29, 2019

Oh ok and is it possible to retrieve this token in app with Dart code ?

@pcg92
Copy link
Contributor

pcg92 commented Jan 29, 2019

Why do you need login with token?, I think that no, this a server thing, and must be done with the masterkey

@ghost
Copy link
Author

ghost commented Jan 29, 2019

Because it's the way that I have to login on my server like this : https://docs.parseplatform.org/android/guide/#setting-the-current-user

@pcg92
Copy link
Contributor

pcg92 commented Jan 29, 2019

You can do the normal way:
https://docs.parseplatform.org/android/guide/#logging-in

This is implemented in this sdk, with username and password

This issue was closed.
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

1 participant