Conversation
e8b2d7a to
a559969
Compare
3c1205d to
95544ea
Compare
| } | ||
|
|
||
| public async refreshCustomData() { | ||
| await this.refreshAccessToken(); |
There was a problem hiding this comment.
So in reality, an exception is thrown, right?
There was a problem hiding this comment.
Yeah, for now :) Until #2967 gets fixed.
|
what does this means
I find it problematic to have the return type differ. Sometimes returning |
Ideally this would just be It's because Realm Web sends a request (like the legacy SDKs) but that doesn't seem to be implemented in the way Object Store logs out a user - or it's implemented in a way that allows it to fail silently. I propose we change it to make Realm JS return a resolved |
|
exactly what I was thinking. if its a synchronous call in some cases this should return a resolved Promise. |
packages/realm-web/src/App.ts
Outdated
| > = await User.logIn(this, credentials, fetchProfile); | ||
| // Add the user at the top of the stack | ||
| this.users.splice(0, 0, handle); | ||
| this.users.splice(0, 0, user); |
There was a problem hiding this comment.
unshift would just take the user.
| @@ -153,13 +114,7 @@ export class User implements Realm.User { | |||
| private _state: Realm.UserState; | |||
| private transport: AuthenticatedTransport; | |||
There was a problem hiding this comment.
A bit inconsistency in prefixing props marked as private with _.
Have we considered to switching away from TS public/private keyword (which doesn't translate ti JS), and adopt JS private class fields.
I'm pretty sure latest versions of TS will emulates the runtime behaviour of private fields the best it can.
There was a problem hiding this comment.
The private fields with an _ prefix is only because the class also has a public getter overloading the name. It could be called internalState or something else. But I actually think this specific fields goes away in one of the later PRs.
With regards to JS private fields. It's valuable to keep an eye on, but I don't think the adoption in browsers are good enough for us to rely on. And I don't know the state of polyfils for this?
There was a problem hiding this comment.
I think TS handles that, but I'm not sure (as in I haven't tested it) microsoft/TypeScript#30829
5c68a02 to
e88cbd5
Compare
40bd1e7 to
b7476c1
Compare
Co-authored-by: Kenneth Geisshirt <kenneth.geisshirt@mongodb.com>
b7476c1 to
de28eb4
Compare
packages/realm-web/src/App.ts
Outdated
| } | ||
| public switchUser(nextUser: User<FunctionsFactoryType, CustomDataType>) { | ||
| const index = this.users.findIndex(u => u === nextUser); | ||
| if (index >= 0) { |
There was a problem hiding this comment.
index !== -1 might be more precise
| public async removeUser(user: User<FunctionsFactoryType, CustomDataType>) { | ||
| // Remove the user from the list of users | ||
| const index = this.users.findIndex(({ user: u }) => u === user); | ||
| const index = this.users.findIndex(u => u === user); |
There was a problem hiding this comment.
If not, findIndex will return -1, which would result in a bug, since the first argument of splice states:
An integer that specifies at what position to add/remove items, Use negative values to specify the position from the end of the array
types/app.d.ts
Outdated
| logOut(): Promise<void>; | ||
|
|
||
| /** | ||
| * Link the user with a new identity represented by another set of credentials. |
There was a problem hiding this comment.
| * Link the user with a new identity represented by another set of credentials. | |
| * Link the user with an identity represented by another set of credentials. |
types/app.d.ts
Outdated
| linkCredentials(credentials: Credentials): Promise<void>; | ||
|
|
||
| /** | ||
| * Call a remote MongoDB Realm function by it's name. |
There was a problem hiding this comment.
| * Call a remote MongoDB Realm function by it's name. | |
| * Call a remote MongoDB Realm function by its name. |
* Renamed UserAPIKeyProvider to ApiKeyAuth * Renaming instance methods * Moved from user.auth.apiKeys to user.apiKeys * Renamed js_user_apikey_provider.hpp to js_api_key_auth.hpp * Updated the jsdocs * Adding apiKeys to the browser proxy * Adding a note in the changelog
349b594 to
a65b534
Compare
* Renamed to js_email_password_auth.hpp, email-password-auth-methods.js and api-key-auth-methods.js
* Adding a note in the changelog
* Updated docs
* Renamed to EmailPasswordAuth
* registerEmail -> registerUser
* Realm.User.identity -> Realm.User.id. Realm.User.token -> Realm.User.accessToken. Add Realm.User.refreshToken.
* Turn Realm.App.{currentUser, allUsers} to an instance property
* Add Realm.Auth.EmailPassword.callResetPasswordFunction
* Wrongly merged
What, How & Why?
The purpose of this PR is to merge duplicated type definitions (such as
App,User,UserProfile) across ´types/index.d.ts` and the other files in that directory.I propose the following changes to the Realm JS types:
Userrelated changes:identityonUsertoid(to align with other SDKs and avoid confusion from authentication provideridentitiesreturned when fetching the user profile).tokentoaccessToken(to make it more obvious what token this is) and add therefreshTokenas a property (this is up for debate - but it makes it easier to test the User implementation).customDatato use a generic type defined byUserand theApp(like we do forFunctionsFactoryType) to allow users of the API to define types for this custom data, once (when creating the app instance).logOuttoPromise<void> | void, since it sends a request to invalidate the refresh token.Apprelated changes:allUsersfrom a method to a getter-property returning a list instead of aUserMap.currentUserfrom a method to a getter-property.removeUserreturn aPromise<void>instead ofPromise<User>, since that user would have limited use anyway.Authrelated changes:API*toApi.Authto the class names (Realm.Auth.ApiKeyAuthandRealm.Auth.EmailPasswordAuth).callResetPasswordFunctionwhich was part of the existing Stitch SDK.I propose the following changest to the Realm Web Types:
Apprelated changes:stringas a valid argument on methods called with a user parameter (it was ment to enable users to pass in a user ID instead of a user object).UserProfilerelated changes:pictureURLtopictureUrl.Authrelated changes:ApiKeyProvidertoApiKeyAuth.EmailPasswordProvidertoEmailPasswordAuth.getandlisttofetchandfetchAllrespectively, on theApiKeyProvider.resendConfirmationtoresendConfirmationEmailon theEmailPasswordProvider.These changes lead to some simplifications of the way user state is managed by the app, which also found its way into this PR.