-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add guest user #795
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
feat: add guest user #795
Conversation
I think the events make sense when you listen to a specific object / instance.
Maybe it makes things easier to work with (with current design of nextcloud-auth) when having a global event like |
That would differenciate for other like
|
114b450 to
b9568cc
Compare
Signed-off-by: skjnldsv <[email protected]>
|
Done! With tests! |
Signed-off-by: skjnldsv <[email protected]>
| /** | ||
| * Get the currently Guest user or null if not logged in | ||
| */ | ||
| export function getGuestUser(): GuestUser { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either
| export function getGuestUser(): GuestUser { | |
| export function getGuestUser(): NextcloudUser { |
Or we would need to also export the type of GuestUser.
|
|
||
| class GuestUser implements NextcloudUser { | ||
|
|
||
| private _displayName: string | null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we would export this class type (skip this depending on the other comment), then the type includes this private field.
Also it is accessible and only marked private for typescript.
You might consider instead using standard ES visibility:
| private _displayName: string | null | |
| #displayName: string | null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought # was dropped in the end? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No they are standardized in es2019:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties
Its more like protected but enforced by runtime, meaning you cannot access the property from outside the class.
Whereas the typescript private, protected, and readonly are just types which get stripped away:
Meaning you could still access those private fields, while #something will throw an exception:

In the end its not really important, both have good reasons to use or not to use, it depends :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, absolutely!
But I remember using the # a while back, when it was drafted and about to be accepted.
But I also remember that we rolled back and stopped using it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are some places using it, but it really is not that important.
If you mess with private fields you better know what you are doing, so its your risk.
Meaning its just a matter of taste if you prefer Typescript sugar or Javascript syntax.
E.g. a benefit of Typescript sugar is that you can unit test it (while also there are some guidelines that discurage you from testing private properties, but thats another topic^^).
susnux
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but we need the type adjusted or exported
https://github.com/nextcloud-libraries/nextcloud-auth/pull/795/files#r2077161323
|
Damn did not saw the auto merge 😮💨 |
|

Features:
getGuestUsermethod that looks similar to a normal userCode snippet example