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

Generated client has type error when using optional AuthParams #1131

Open
tuckers-tech opened this issue Apr 7, 2024 · 0 comments
Open

Generated client has type error when using optional AuthParams #1131

tuckers-tech opened this issue Apr 7, 2024 · 0 comments

Comments

@tuckers-tech
Copy link

tuckers-tech commented Apr 7, 2024

I have a system that authenticates via secure cookie or api token (depending on if the client is the browser or CLI). I currently have this set up on the encore side with:

interface AuthParams {
  cookie?: Header<'Cookie'>
  token?: Header<'x-api-token'>
}

This works great on the backend side, I didn't run into any issues until I started integrating the client. I can generate the client but when I try and build (exec TS check) I'm running into an issue with the following generated lines in the callAPI method

if (authData) {
  init.headers['cookie'] = authData.cookie
  init.headers['x-api-token'] = authData.token
}

This throws the following error because both authData.cookie and authData.token are optional

Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.
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

1 participant