Backendless Support
 
Solved

Backendless.UserService.register

Hello,

The Backendless.UserService.register() method returns a backendless user object that isn't exposing the user objectId. Now, this is based on the Backendless.d.ts. I'm not sure what is returned at run time but this is causing precompile errors in my software. I've recently updated the backendless version in my application.

Thanks,

Dan

Leave a Comment

Comments (18)

photo
1

Appears to be the same for getCurrentUser. Why wouldn't it return the data from all columns?

photo
1

Also, Backendless.d.ts is specifying LocalCache.clear(key:string). However, the actual call in local-cache/index.js doesn't take a parameter. so, the actual call and spec do not match.

Dan

photo
1

Hello Dan,

Could you please prepare a sample to reproduce the problem?

photo
1

For Backendless.LocalCache.clear

My Code

loginValid() {

let userTokenIsValid = Backendless.UserService.isValidLoginSync();

console.log('app.account.ts loginValid', userTokenIsValid);

if (!userTokenIsValid) {

Backendless.LocalCache.clear();

}

return userTokenIsValid;

}

Backendless.d.ts

interface LocalCacheI {

enabled:boolean;

exists(key:string):boolean;

set(key:string):boolean;

set<T>(key:string, val:T):T;

remove(key:string):boolean;

get(key:string):any;

getAll():Object;

getCachePolicy(key:string):Object;

serialize(value:any):string;

deserialize(value:string):any;

clear(key:string):void;

flushExpired():void;

}

Local-cache/index.ts

store.clear = function() {

storage = {}

}

photo
1

The object returned for the register method is if type User (backendless.d.ts)

My code

Backendless.UserService.register(user)

.then((registeredUser) => {

console.log('app.account.ts register register user success', JSON.stringify(registeredUser));

//set member relationship between user and member

Backendless.Data.of(AppConfig.TABLE.Users).setRelation({ objectId: registeredUser.objectId }, 'member', [{ objectId: member.objectId }])

.then((count) => {

console.log('app.account.ts register setRelation success', count);

resolve(registeredUser);

})

.catch((err) => {

console.log('app.account.ts register setRelation error', JSON.stringify(err));

reject(err);

});

})

.catch((err) => {

console.log('app.account.ts register register user error', JSON.stringify(err));

reject(err);

});

Backendless.d.ts

/**

* @public

* @class Backendless.User

* @constructor

*/

class User {

___class:string;

username:string;

password:string;

email:string;

}

photo
1

I suppose the User class declaration is missing some default fields, objectId in particular.

Our JS engineer will contact you here soon with more details.

photo
photo
1

excellent. Thanks.

photo
1

Hi Dan

I've created an internal ticket BKNDLSS-16147 for resolve all the problems with type-definitions, we will notify you when it fixed and new version is released asap

Regards, Vlad

photo
1

thanks

photo
1

Dan, I have a quick question to you =)

did you have this error "Module ''backendless'' has no default export."?

I have "typescript@2.2.2"

I know how to fix it but I want to be sure that my fix will not broke code of other developers. I'm going to change this one JS-SDK/backendless.d.ts#L963 to this "export default Backendless;"

photo
1

i didn't see that error

photo
1

btw, i have typescript version 2.4.0

photo
1

ok, thank you

photo
photo
1

how do you import "Backandless" package in your code?

like this: "import Backendless from 'backendless';" ?

photo
1

correct

import Backendless from 'backendless';

photo
1

please upgrade the js-sdk to version 4.1.8

photo
1

what you can do now:

.../user.ts

  1. import Backendless from 'backendless';
  2. interface UserI {
  3. email: string;
  4. password: string;
  5. name: string;
  6. age: number;
  7. }
  8. export default class AppUser extends Backendless.User {
  9. email: string;
  10. password: string;
  11. name: string;
  12. age: number;
  13. constructor(user: UserI) {
  14. super();
  15. this.email = user.email;
  16. this.password = user.password;
  17. this.name = user.name;
  18. this.age = user.age;
  19. }
  20. }

.../user-service.ts

  1. import {Injectable} from '@angular/core';
  2. import Backendless from 'backendless';
  3. import AppUser from './user';
  4. @Injectable()
  5. export class UserService {
  6. register(user: AppUser): Promise<AppUser> {
  7. return Backendless.UserService.register<AppUser>(user);
  8. }
  9. login(email: string, password: string): Promise<AppUser> {
  10. return Backendless.UserService.login<AppUser>(email, password, true);
  11. }
  12. getCurrentUser(): Promise<AppUser> {
  13. return Backendless.UserService.getCurrentUser<AppUser>();
  14. }
  15. }

photo
1

worked beautifully. thanks to all.