Skip to content

fix(ctrl): Add fallback for null defaultOrganization during OIDC login#183

Merged
lbroudoux merged 1 commit into
reshaprio:mainfrom
Vaishnav88sk:issue-182-default-organization
Jun 9, 2026
Merged

fix(ctrl): Add fallback for null defaultOrganization during OIDC login#183
lbroudoux merged 1 commit into
reshaprio:mainfrom
Vaishnav88sk:issue-182-default-organization

Conversation

@Vaishnav88sk

Copy link
Copy Markdown
Contributor

Fixes the NullPointerException during OIDC login when a user's defaultOrganization is unset.
The AuthenticationController now checks if the default organization is null. If it is, it automatically falls back to the first organization the user is a member of, allowing JWT token generation to succeed gracefully.

Related Issues:
Fixes #182

@Vaishnav88sk Vaishnav88sk requested a review from lbroudoux as a code owner June 8, 2026 17:02

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have used 403 instead of 400 and I think some code can be extracted into the same utilitty method to avoid duplication.

@Vaishnav88sk

Copy link
Copy Markdown
Contributor Author

You are completely right about the 403 Forbidden - that is much more semantically accurate since the request is valid but lacks permissions. I will also extract the organization resolution and token generation logic into a single utility method to DRY up the controller. Since I have less experience with code architecture, I sometimes make mistakes in these situations 😉.

I'll push those changes up shortly!

Ensures that if a user's defaultOrganization is null, the AuthenticationController automatically falls back to the first available organization instead of throwing a NullPointerException during JWT token generation.

Signed-off-by: Vaishnav88sk <vaishnavsk8804@gmail.com>
@Vaishnav88sk Vaishnav88sk force-pushed the issue-182-default-organization branch from 5904d77 to d88eefd Compare June 9, 2026 12:45
@Vaishnav88sk

Copy link
Copy Markdown
Contributor Author

I've just pushed an update to address both points:

  1. Changed 400 to 403 Forbidden: You're absolutely right! Since the request is perfectly valid and the user is authenticated, but they just lack the required organization membership, a 403 Forbidden is the semantically correct status code.
  2. Extracted Utility Method: I pulled the duplicated organization resolution and token generation logic into a single resolveOrganizationAndGenerateToken utility method to keep the controller DRY.

Let me know if everything looks good!

@Vaishnav88sk Vaishnav88sk requested a review from lbroudoux June 9, 2026 12:48

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks all good. Thanks for the changes.

@lbroudoux lbroudoux added this to the 0.0.14 milestone Jun 9, 2026
@lbroudoux lbroudoux merged commit 092799b into reshaprio:main Jun 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

defaultOrganization may be unset and causes errors during authentication

2 participants