Skip to content

parseUser.currentUser() & .getCurrentUserFromServer() #24

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 10, 2019 · 9 comments
Closed

parseUser.currentUser() & .getCurrentUserFromServer() #24

ghost opened this issue Jan 10, 2019 · 9 comments

Comments

@ghost
Copy link

ghost commented Jan 10, 2019

Hello,

I copy/paste the project example, put my applications constants.

I sign up a user and login it. (I have the user in database with the session, it's good)

I restart my application and do my own code :
checkCurrentUser() async { // Best practice for starting the app. This will check for a var user = ParseUser.currentUser(); user = await user.getCurrentUserFromServer(); print("user: $user"); }

But in my terminal, I have this :
I/flutter (13889): I/flutter (13889): ---- I/flutter (13889): Hello Flutter API Response (_User : ParseApiRQ.currentUser) : I/flutter (13889): Status Code: 200 I/flutter (13889): Payload: {objectId: LjTOWTPE8D, createdAt: 2019-01-10T12:51:19.140Z, email: [email protected], username: TestFlutter, updatedAt: 2019-01-10T12:51:19.140Z, ACL: {*: {read: true}, LjTOWTPE8D: {read: true, write: true}}, sessionToken: r:5f7045a813f163282ac8a765eabf8cb6, __type: Object, className: _User} I/flutter (13889): ---- I/flutter (13889): user: Username: null I/flutter (13889): Email Address:null

The problem is that it seems that the user is retrieved but when I print my user variable, it's null.

In advance, thank you.

@phillwiggins
Copy link
Member

phillwiggins commented Jan 10, 2019 via email

@phillwiggins
Copy link
Member

Should be fixed now.

@ZeroNilZero
Copy link

why ParseUser.currentUser() return Future?
it make a lot headache!

@fischerscode
Copy link
Contributor

@ZeroNilZero
Almost everything in this SDK returns a future. As futures are a great way of dealing with asynchronous actions and even provide a way for handling errors.

If you have a case where using a future is not possible, you might have a lock at this.
But I would not recommend using it in production, as such a case should be the result of a design flaw.

@ZeroNilZero
Copy link

@maaeps
How can we access and use currentUser in custom ParseObject? and do some action base on it?

@fischerscode
Copy link
Contributor

I assume you have a custom ParseUser class as described here (but with extending ParseUser) class and want to get the current user as an instance of your custom class.

You can use provide a parseUserConstructor (only available in 1.0.27) or you can use ParseUser.currentUser(customUserObject: YourCustomUserClass())

@ZeroNilZero
Copy link

@maaeps
I'm not talking about custom USER class, I want to use current user in another Object Class and do something like this:
ParseObject get O => this.user.objectId == ParseUser.currentUser().objectId ? A : B;
which A and B are Pointer ParseObject.

@ZeroNilZero
Copy link

I assume you have a custom ParseUser class as described here (but with extending ParseUser) class and want to get the current user as an instance of your custom class.

You can use provide a parseUserConstructor (only available in 1.0.27) or you can use ParseUser.currentUser(customUserObject: YourCustomUserClass())

How can I add this version?

@fischerscode
Copy link
Contributor

Like this?
Future<ParseObject> get O async => this.user.objectId == (await ParseUser.currentUser()).objectId ? A : B;

To use 1.0.27 in your app (not released yet!)
replace
parse_server_sdk: ^1.0.26
in your pubspec.yaml with

  parse_server_sdk:
    git:
      url: git://github.com/parse-community/Parse-SDK-Flutter.git
      ref: release/1.0.27

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

3 participants