mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
feat(oidc): use the picture claim as avatar when none is uploaded
When a user signs in via OIDC and hasn't uploaded a custom avatar, their `picture` claim is now used as their avatar. The users.avatar column holds either an uploaded file name or an absolute https URL from the claim, and a single resolver on each side (server avatarUrl, client avatarSrc) renders both. An uploaded avatar always wins and is never overwritten; the picture refreshes on each login otherwise. Only https URLs are stored, matching the image CSP. All the scattered /uploads/avatars/ builders now go through the resolvers, which also fixes collection member avatars that were rendering a bare file name. Discussion #1399
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
/**
|
||||
* Resolve a user's stored avatar reference to a renderable URL.
|
||||
*
|
||||
* The value is either an uploaded file name (served from /uploads/avatars) or,
|
||||
* for SSO users who never uploaded one, an absolute https URL taken from their
|
||||
* OIDC `picture` claim (#1399) — that one is passed through untouched.
|
||||
*/
|
||||
export function avatarUrl(user: { avatar?: string | null }): string | null {
|
||||
return user.avatar ? `/uploads/avatars/${user.avatar}` : null;
|
||||
if (!user.avatar) return null;
|
||||
if (/^https:\/\//i.test(user.avatar)) return user.avatar;
|
||||
return `/uploads/avatars/${user.avatar}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user