Skip to content
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

[Feature Request] enhance function's user parameter id, expected to be string | undefined #1914

Closed
cqh963852 opened this issue Dec 14, 2024 · 5 comments

Comments

@cqh963852
Copy link

Is your feature request related to a problem? Please describe.

While using zenstack with next-auth@5. ts show me Type 'undefined' is not assignable to type 'string'.

image

I think in some scenarios, such as user registration, there is no user id at this time.

Describe the solution you'd like

remove the required props;

image

@ymc9
Copy link
Member

ymc9 commented Dec 19, 2024

Hi @cqh963852 , when the user id is not available, what's the expected authorization behavior that you desire? Usually people want to treat it as an anonymous user and if so, you can call enhance with undefined user object.

@cqh963852
Copy link
Author

cqh963852 commented Dec 19, 2024

Hi @cqh963852 , when the user id is not available, what's the expected authorization behavior that you desire? Usually people want to treat it as an anonymous user and if so, you can call enhance with undefined user object.

Thanks for your reply. When the user is anonymous, the User object may not exist (undefined | null).

But currently if I pass a undefined user in the context parameter. ts will reports an error, undefined cannot be assigned to string.

let user: {id:string}|undefined

// this will give an ts error.
enhace(prisma,{user})

@ymc9
Copy link
Member

ymc9 commented Dec 22, 2024

This is unexpected because the enhance API should always allow user to be undefined.
image

What version of ZenStack are you on? Do you have a sharable project?

@cqh963852
Copy link
Author

This is unexpected because the enhance API should always allow user to be undefined. image

What version of ZenStack are you on? Do you have a sharable project?

Sorry I got that wrong earlier.

The enhance can accept a undefined user.

but it requires user's id not be undefined.

The default user id of next-auth may be undefined.

I have also tried rewriting the interface. Since the interface follows the merge, there is no way to change id string | undefined to string

image

@ymc9
Copy link
Member

ymc9 commented Dec 23, 2024

This is unexpected because the enhance API should always allow user to be undefined. image
What version of ZenStack are you on? Do you have a sharable project?

Sorry I got that wrong earlier.

The enhance can accept a undefined user.

but it requires user's id not be undefined.

The default user id of next-auth may be undefined.

I have also tried rewriting the interface. Since the interface follows the merge, there is no way to change id string | undefined to string

image

Got it. The current design of zenstack requires when a user context is provided, it must have a non-nullish id. You'll need to detect the next-auth's case and turn the entire user object to undefined if the id is not available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants