Hello there ,
using Backendless-web
this
final currentUser = await Backendless.userService.currentUser();
print(“currentUser $currentUser”);
will always return null .
this
final currentUser =
await Backendless.userService.findById(loggedInUserId);
print(“currentUser $currentUser”);
will return
PlatformException(error, NoSuchMethodError: tried to call a non-function, such as null: ‘dart.global.Backendless.UserService.findById’, null)
this works .
final userId = await Backendless.userService.loggedInUser();
print(“Getting user $userId”);
Backendless helped me a lot the past few years and I’ve enjoyed learning through it very much.
Hi @ibrahim-omer
Thanks for using Backendless Flutter Web SDK! And thank you a lot for your kind words.
There are some known limitations for Web SDK. Method findById
isn’t currently working for User Service. However you can use Data Service to find the necessary user by id:
var user = Backendless.data.withClass<BackendlessUser>().findById('USER_ID');
Can you please provide the code sample you use to log in the user? Do you use stayLoggedIn
option?
Best Regards,
Maksym
I’ve just tried to reproduce your issue and got the following results:
void login() async {
var user = await Backendless.userService.login('email', 'password', true);
var current = await Backendless.userService.currentUser();
var logged = await Backendless.userService.loggedInUser();
print('User: $user');
print('Current: $current');
print('Logged: $logged');
}
User: BackendlessUser {...}
Current: BackendlessUser {...}
Logged: UserStringId
Make sure you make the currentUser()
call after the user is logged in. Use the await
keyword for async operations.