console: Add user profile hook to show OIDC User details#36188
console: Add user profile hook to show OIDC User details#36188leedqin wants to merge 2 commits intoMaterializeInc:mainfrom
Conversation
- 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.
| .selectNoFrom(sql<string>`current_user`.as("currentUser")) | ||
| .compile(); | ||
| }, []); | ||
| const response = useSqlTyped(query, { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
We should probably handle the loading states. For the footer, maybe a ... and for the menu item, maybe a spinner?
| const { results: sqlRole } = useCurrentUser(); | ||
|
|
||
| return { | ||
| name: name ?? sqlRole, |
There was a problem hiding this comment.
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
- Move useOIDCProfile and useUserProfile to one unfied hook: useSelfManagedProfile.ts - Show sql role in the profile dropdown - use ReactQuery instead of SqlTyped
| // Drop cached session-scoped data so a fresh sign-in doesn't see the | ||
| // previous user's results. | ||
| queryClient.clear(); |
There was a problem hiding this comment.
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
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
useCurrentUserhook to fetch the SQL role of the connected session.useOidcProfilehook to extract and type OIDC user profile claims.useUserProfilehook to unify user identity from OIDC and SQL role.CurrentUserTagcomponent to display the current user in the footer.PageFooterto include theCurrentUserTagfor better user visibility.Verification
How do you know this change is correct? Describe new or existing automated
tests, or manual steps you took.