Skip to content

console: Add user profile hook to show OIDC User details#36188

Open
leedqin wants to merge 2 commits intoMaterializeInc:mainfrom
leedqin:console-oidc-account-details
Open

console: Add user profile hook to show OIDC User details#36188
leedqin wants to merge 2 commits intoMaterializeInc:mainfrom
leedqin:console-oidc-account-details

Conversation

@leedqin
Copy link
Copy Markdown
Contributor

@leedqin leedqin commented Apr 21, 2026

Motivation

We need to show user details when the user is logged in using SSO. Currently using the sql to fetch user information but I also added the hook to fetch any information from OIDC profile and use sql as the fallback if necessary if no claims are set. Fixes: CNS-58

Description

  • Introduced useCurrentUser hook to fetch the SQL role of the connected session.
  • Added useOidcProfile hook to extract and type OIDC user profile claims.
  • Created useUserProfile hook to unify user identity from OIDC and SQL role.
  • Implemented CurrentUserTag component to display the current user in the footer.
  • Enhanced PageFooter to include the CurrentUserTag for better user visibility.

Verification

image image

How do you know this change is correct? Describe new or existing automated
tests, or manual steps you took.

- Introduced `useCurrentUser` hook to fetch the SQL role of the connected session.
- Added `useOidcProfile` hook to extract and type OIDC user profile claims.
- Created `useUserProfile` hook to unify user identity from OIDC and SQL role.
- Implemented `CurrentUserTag` component to display the current user in the footer.
- Enhanced `PageFooter` to include the `CurrentUserTag` for better user visibility.
@leedqin leedqin requested a review from a team as a code owner April 21, 2026 17:02
@leedqin leedqin requested review from SangJunBak and removed request for a team April 21, 2026 17:02
Comment thread src/materialized/ci/listener_configs/oidc.json
Comment thread console/src/hooks/useUserProfile.ts Outdated
Comment thread console/src/hooks/useUserProfile.ts Outdated
.selectNoFrom(sql<string>`current_user`.as("currentUser"))
.compile();
}, []);
const response = useSqlTyped(query, {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know we eventually want to phase out useSqlTyped and the other useSql hooks. I also think this query runs every the user switches pages because it remounts BaseLayout each time. Maybe we just use react query here with a stale time INFINITY then invalidate the react query cache on logout?

Copy link
Copy Markdown
Contributor

@SangJunBak SangJunBak Apr 21, 2026

Choose a reason for hiding this comment

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

We should probably handle the loading states. For the footer, maybe a ... and for the menu item, maybe a spinner?

Comment thread console/src/hooks/useUserProfile.ts Outdated
Comment thread console/src/hooks/useUserProfile.ts Outdated
const { results: sqlRole } = useCurrentUser();

return {
name: name ?? sqlRole,
Copy link
Copy Markdown
Contributor

@SangJunBak SangJunBak Apr 21, 2026

Choose a reason for hiding this comment

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

There's a case where the menu item now shows the user's name and email via the ID token, but this could technically not be the SQL role name. Wonder if we should either:

  • Show the SQL role instead of the name
  • Show all three

@leedqin leedqin added the A-CONSOLE Area: Console label Apr 21, 2026
@leedqin leedqin changed the title Add user profile hook to show OIDC User details console: Add user profile hook to show OIDC User details Apr 21, 2026
- Move useOIDCProfile and useUserProfile to one unfied hook: useSelfManagedProfile.ts
- Show sql role in the profile dropdown
- use ReactQuery instead of SqlTyped
@leedqin leedqin requested a review from SangJunBak April 21, 2026 20:38
Comment on lines +162 to +164
// Drop cached session-scoped data so a fresh sign-in doesn't see the
// previous user's results.
queryClient.clear();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually, looking at the code a bit closer, it seems like all auth methods simply do a browser navigation back to the signin page, meaning the query client is implicitly cleared. We can probably get rid of this line of code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CONSOLE Area: Console

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants