JS Client session identity is generated as optional even though it's marked as required in the spec
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 178
- Forks
- 96
- Avg merge
- 6d 23h
- Merged PRs (30d)
- 3
Description
Preflight checklist
- I could not find a solution in the existing issues, docs, nor discussions.
- I agree to follow this project's Code of Conduct.
- I have read and am following this repository's Contribution Guidelines.
- I have joined the Ory Community Slack.
- I am signed up to the Ory Security Patch Newsletter.
Ory Network Project
No response
Describe the bug
As far as I understood, every session always has a identity in it's response.
This is also the case in the openapi spec under the session, where identity and id are set to be required fields.
But apparently the javascript/typescript client does not generate it as such, and generates it as a optional field in the Session type. This causes issues in our project down the road, because we would either have to do unnecessary checks all over the place just to satisfy TypeScript in that reagard, or overwrite your internal Session type such that the identity is not optional.
Reproducing the bug
Create a typescript project,
- Call
toSession({...})on aFrontendApiclient instance. - Try accessing the
session.identity.idattribute, which fails - Note that typescript is telling you that the "identity might be undefined"
Relevant log output
'session.identity' is possibly 'undefined'.ts(18048)
(property) Session['identity']?: Identity | undefined
@type — {Identity}
@memberof — Session
Relevant configuration
No response
Version
Kratos 1.0.0 and the latest npm client
On which operating system are you observing this issue?
Linux
In which environment are you deploying?
Docker
Additional Context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the OpenAPI session definition, where identity and id are required, with the generated Session type used by FrontendApi.toSession. Trace the client generation input and output to find where identity becomes optional. Done means the generated TypeScript type reflects the required spec and session.identity.id no longer produces the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100