Trying to find a complete example of extending (adding functionality) Parse.User
. There is alot out there for extending other objects, but it seems Parse.User
(and also Parse.Role
and Parse.Installation
) are special exceptions.
There are a few SO posts out there with answers, but unfortunately the links that they point to are the old parse.com site, which don't map up to the new site.
Let's say we have an extra field in the User
table/class called IsAdmin
and I want to add an extra method to check for that field (Yes can use Parse.User.getCurrent().get('IsAdmin)
, but this is just an example). As far as I can tell, albeit with snippets of examples from here and there, I "think" it sort of looks like this:
/**
* I "think" you need this. Docs don't explain how its fully used
*/
Parse.User.allowCustomUserClass(true);
export class User extends Parse.User {
constructor() {
super('User');
}
isThisUserAnAdmin(): boolean {
return !(!this.get('IsAdmin));
}
}
Parse.Object.registerSubclass('User', User);
/**
* Then I want to use it and call specific 'Parse.User' superclass
* functions + get the actual `User` model and NOT the `Parse.User`
*/
const makeAnAdmin = async (email: string, password: string): Promise<User> => {
return User.signUp(email, password,
{
email: email,
isAdmin: false
}
);
}
Again, looks ugly, but this is a mish-mash of what I could find. Also feel free to tell me off if there is an obvious answer in the docs as I've been bashing my head on this all day.