fix(register): fallback image in user avatar selection

Previously, the method to generate the fallback image returned the
image given by the auth provider, if existing. It now includes a
new flag to foce the generation of a fallback image.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson
2026-01-14 20:56:03 +01:00
committed by Philip Molares
parent f999dd31e2
commit 4099c4aa4e
2 changed files with 12 additions and 8 deletions
@@ -35,11 +35,14 @@ export const ProfilePictureSelectField: React.FC<ProfilePictureSelectFieldProps>
username,
value
}) => {
const fallbackUrl = useAvatarUrl({
username,
photoUrl,
displayName: username
})
const fallbackUrl = useAvatarUrl(
{
username,
photoUrl,
displayName: username
},
true
)
const profileEditsAllowed = useFrontendConfig().allowProfileEdits
const onSetProviderPicture = useCallback(() => {
if (value !== ProfilePictureChoice.PROVIDER) {
@@ -13,18 +13,19 @@ import type { UserInfoInterface } from '@hedgedoc/commons'
* When the user has no photoUrl, a random avatar is generated from the display name.
*
* @param user The user for which to get the avatar URL
* @param forceFallback Whether to force the fallback avatar even if the user has a photoUrl
* @return The correct avatar url for the user
*/
export const useAvatarUrl = (user: UserInfoInterface): string => {
export const useAvatarUrl = (user: UserInfoInterface, forceFallback = false): string => {
const { photoUrl, displayName } = user
return useMemo(() => {
if (photoUrl && photoUrl.trim() !== '') {
if (photoUrl && photoUrl.trim() !== '' && !forceFallback) {
return photoUrl
}
const avatar = createAvatar(identicon, {
seed: displayName
})
return avatar.toDataUri()
}, [photoUrl, displayName])
}, [photoUrl, displayName, forceFallback])
}