Skip to content

Show profile pictures from sign-in providers in the control plane - #404

Merged
tnkuehne merged 3 commits into
mainfrom
user-profile-photos
Nov 25, 2026
Merged

tnkuehne merged 3 commits into
mainfrom
user-profile-photos

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The sidebar's account menu and the member list now show each person's profile picture from their sign-in provider, with initials when there is none.

Better Auth already saves the provider's picture claim as user.image when it creates a user from a Google or company OIDC sign-in. Nothing displayed it.

Changes

  • Display: a shared UserAvatar renders the picture with initials as fallback in the sidebar and on Settings → Members. Initials now use the first letter of up to two name parts in both places ("AL" instead of "AD"). The image request sends no referrer.
  • Refresh on sign-in: Better Auth copies the picture only at sign-up. Its overrideUserInfoOnSignIn option would also overwrite the name and email on every sign-in. A small sign-in-picture plugin instead reads the picture claim from the ID token of the account just used (/callback/:id and /sso/callback/:providerId) and updates only image. A sign-in without a usable picture, such as Microsoft, keeps the current one.
  • Validation: profileImage in the contracts accepts only HTTPS URLs up to 2048 characters. Other stored values are shown as initials.
  • API: GET /members returns image with each member, matching the UI.

Company OIDC providers that send the picture only from the userinfo endpoint get it at sign-up, but later sign-ins don't refresh it.

Screenshots

Synthetic users. Ada and Grace have pictures; Linus has none.

Before After
Light, 1280 px
Dark, 1280 px
Light, 390 px
Dark, 390 px

Checked: the sidebar account menu and the member list at 1280 and 390 px, light and dark, with and without a picture. Not checked: a picture URL that fails to load (bits-ui then shows the fallback).

Verification

  • social-sign-in.test.ts: Google sign-ins set and then replace the picture without changing name or email; an http picture and a Microsoft sign-in leave it unchanged. Fails without the plugin.
  • company-sso-plugin.integration.test.ts: a company OIDC sign-in whose picture is only in the ID token stores it. Fails without the plugin.
  • Organization, organization SSO, email admission and organization login suites pass. svelte-check, Oxlint and Oxfmt are clean.

RetriggerView in GreptileConfidence Score: 5/5

The latest changes appear safe to merge.

Summary

Shows provider pictures in the sidebar and member list, with initials as fallback.

  • The sidebar and member list show provider pictures with initials as a fallback.
  • Sign-ins refresh profile pictures without changing names or email.

Both earlier unnumbered comments are addressed. No new actionable issues were found in the latest changes.

Reviews (2) · Last reviewed commit: "Separate the returning sign-in steps" · Reviewed by Greptile

Better Auth stores the provider's picture when it creates a user, but the
sidebar and the member list only showed initials. Both now show the
picture and fall back to initials.

Better Auth copies the picture only at sign-up, and its option to refresh
the profile on each sign-in also overwrites the name and email. A small
plugin refreshes just the picture from the ID token after each personal or
company sign-in. Only HTTPS pictures are stored and shown; a sign-in
without one keeps the current picture.

The members API returns the picture with each member.
@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Comments Outside Diff

No findings outside the diff remain.

@tnkuehne

Copy link
Copy Markdown
Contributor Author

Both fixed: initials now take the first whole character (Array.from(part)[0]), and the company SSO test completes a second callback with a new picture and checks that only image changes. (6c91318)

@tnkuehne
tnkuehne merged commit f948f11 into main Nov 25, 2026
15 of 17 checks passed
@tnkuehne
tnkuehne deleted the user-profile-photos branch November 25, 2026 16:23
tnkuehne added a commit that referenced this pull request Nov 25, 2026
Each Google, Microsoft or company SSO sign-in now copies the person's
picture into the control plane's own store. Pages load it from
Widefleet, never from the provider. Microsoft and Entra pictures, which
have no URL, appear as well.

## Why

The control plane showed provider picture URLs directly (#404).
Microsoft and Entra supply the photo only as bytes from Microsoft Graph,
and apps cannot load pictures from another origin. One copy per person
covers every provider and gives apps a picture to serve (follow-up PR).

## Changes

- **Copy on sign-in:** The `sign-in-picture` plugin runs after
`/callback/:id` and `/sso/callback/:providerId`.
- Microsoft and Entra: it fetches `/me/photos/120x120/$value` from Graph
with the sign-in's access token.
- Google and company OIDC: it reads the ID token's `picture` claim. When
the ID token names none, it reads the user info with the sign-in's
access token: Google's (`openidconnect.googleapis.com/v1/userinfo`) for
personal Google sign-in, because Google leaves `picture` out of
Workspace accounts' ID tokens, and the connection's discovered endpoint
for company SSO.
- Which hosts it asks (`fetchPictureUrl`): only the provider's own
origin, which receives the access token like its other endpoints, and
Google's account picture host. Other hosts are never contacted, so no
DNS check is needed. Redirects are not followed.
- **Scopes:** Personal Microsoft sign-in requests `User.Read`. Saving an
Entra company SSO connection adds `User.Read`, which its registration
already grants for app membership checks.
- **Validation:** PNG, JPEG, GIF or WebP up to 100 KB. The bytes decide
the type; SVG is never stored. The fetch and validation live in
`@platform/auth-proxy/picture`, so the app proxy can use them in the
follow-up.
- **Store:** A new `user_picture` table holds one row per user, outside
the `user` row that Better Auth reads on every session lookup.
  - Deleting a user deletes the row (foreign key cascade).
- Each write locks the user's row, so concurrent sign-ins leave the copy
and `user.image` in agreement.
- A sign-in whose picture cannot be read keeps the current copy. A
provider that reports none (no `picture` in the ID token or user info,
or Graph `404`) removes it.
- **`user.image`:** Holds `/users/{id}/picture?v={version}`, never a
provider URL. The contract `profileImage` accepts only that path. A
provider URL that Better Auth stores at sign-up is cleared when no copy
can be made.
- **Claims:** Widefleet's own ID tokens and user info carry `picture` as
an absolute URL on the installation.
- **Route `/users/{id}/picture`:**
- Who sees what: a person always sees their own picture; others see it
only as an administrator of an organization both belong to, the same
rule as the member list. An organization that requires company SSO
counts only for a company sign-in.
- Caching: `ETag` with `Cache-Control: private, no-cache`, so the check
runs on every view and removal from an organization takes effect.
- Safety headers: `nosniff`, a sandboxing CSP and `same-origin` resource
policy.
- `users` joins the reserved organization slugs like the other top-level
pages.

Existing Entra connections request `User.Read` after their next save in
**Company sign-in**. Company OIDC providers that host pictures elsewhere
than their own origin or Google's picture host show initials.

## Documentation

`apps/docs/docs/reference/social-sign-in.md` says Microsoft sign-in
requests `openid`, `profile` and `email`. It now also requests
`User.Read`. Draft docs PR: #411.

## Verification

- `packages/auth-proxy/src/picture.test.ts`:
- Fetching: type detection by bytes (SVG and HTML rejected), size limit,
`404` vs. failure, no redirects.
- Hosts: only the provider origin, which gets the bearer token, and
Google's picture host; other, private and credentialed hosts are never
requested.
  - Graph: request with the bearer token.
- `social-sign-in.test.ts`: Google copies the picture and leaves name
and email unchanged. SVG and `http` pictures are not copied. A Workspace
sign-in without the claim copies the picture from Google's user info,
keeps the copy when user info fails, and reports none when user info
names none. Microsoft asks Graph with the stored access token.
- `company-sso-plugin.integration.test.ts`: a company OIDC sign-in
stores a copy from its ID token; a returning sign-in that names a new
picture only in its user info replaces the copy. Both cover registered
and migrated (runtime-discovered) connections.
- `user-pictures.integration.test.ts`: replacing and removing a copy;
cascade on user deletion; visibility for the owner, an administrator of
a shared organization, and not for members, other organizations, an
organization that requires company SSO, or after leaving.
- `organization-settings.integration.test.ts`: a saved Entra connection
requests `User.Read`.
- `organization-sso.integration.test.ts`: Widefleet's app sign-in ID
token and user info carry the absolute picture URL.
- Rendered the member list and sidebar from a real server with copied
pictures: all three images load through the route with the session
cookie. The look is unchanged from #404.
- `svelte-check`, Oxlint and Oxfmt are clean.
`runtime-errors.integration.test.ts` needs a built server and fails on
`main` the same way locally.

Not verified against a real Microsoft tenant: the Entra and personal
Microsoft Graph calls are covered with synthetic responses.






<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><ruby><rp>Confidence Score: 5/5 · The PR appears safe to merge; no
new actionable issues were found.</rp></ruby><a
href="https://app.greptile.com/api/retrigger?id=119692309&amp;sig=83e8ab2ccf6f4e33625d86284702156c2f94e504e1754c48223fe620121d4272"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F407&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5</h2>

<!-- greptile-impact-verdict --> The PR appears safe to merge; no new
actionable issues were found.

<details open><summary><h3>Summary</h3></summary>

Copies provider pictures into `user_picture` during sign-in and serves
them through an access-checked route.
- Sign-ins copy profile pictures into Widefleet’s own store.
- The control plane serves profile pictures through a checked Widefleet
route.
</details>

<details open><summary><h3>Diagram</h3></summary>

```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Provider sign-in] --> B[Read picture claims or Graph photo]
  B --> C[Check host, size and image type]
  C --> D[Lock user row]
  D --> E[Save picture and local path together]
  E --> F[Picture request]
  F --> G[Check current access]
  G --> H[Return image or 304]
```
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (6) · Last reviewed commit: ["Keep the picture when user
info
discover..."](b6e9332)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>

<!-- /greptile_comment -->
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

Successfully merging this pull request may close these issues.

1 participant