Conversation
|
thanks! some references where really outdated + i tried to clarify in #1493 does that make it clearer? best, |
|
Thanks @sjvans this looks a lot better! I just miss some pointers on the |
|
the anonymous and privileged users should be checked via system/ technical users, on the other hand, are identified via a pseudo role and should be checked via best, |
|
for a privileged user, the btw, why do you need to know if it is the anonymous user? non-anonymous users have pseudo role |
|
I tried to use cds.User.Anonymous in a test today, but I am having trouble. In the middleware I check if user is anonymous with this code: if (!cds.context?.user.is('authenticated-user')) {
next();
return;
}In the test I would expect to use something like it('handles request with anonymous user correctly', async () => {
cds.context = { user: new cds.User('anonymous') } as EventContext;
const nextMock = jest.fn();
await initUser({} as XssecExpressRequest, {}, nextMock);
expect(cds.context.user.id).toBe('anonymous');
expect(nextMock).toHaveBeenCalledWith();
});It would be more convenient to use |
|
@sjvans is this a new feature? We are on cds 8.5.0 and I get |
no. that's been there a long time. the sealed instances were added in v6.0.0, the classes are even a lot older. cf. node repl: Welcome to Node.js v22.8.0.
Type ".help" for more information.
> const cds = require('@sap/cds')
undefined
> cds.User
[Function: exports] {
default: [Getter/Setter],
anonymous: Anonymous {},
Anonymous: [class Anonymous extends User],
privileged: Privileged {},
Privileged: [class Privileged extends User],
_default: Anonymous {}
}
> cds.User.Anonymous
[class Anonymous extends User]
> cds.User.anonymous
Anonymous {}@daogrady could you please assist re typescript? |
|
Gladly! Feel free to just send me a meeting request so we can work this out. |
re #1483 --------- Co-authored-by: Mahati Shankar <93712176+smahati@users.noreply.github.com>
This is unfinished text, so please do not merge.
When migrating to CDSv8 (from 7) we did have a few issues, especially on middleware related to the user.
Please update your documentation, it is missing these points currently afaik.