-
-
Notifications
You must be signed in to change notification settings - Fork 130
feat(users): add libravatar / gravatar support #4277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,22 @@ | ||
| import type { MantineSize } from "@mantine/core"; | ||
|
|
||
| import { auth } from "@homarr/auth/next"; | ||
| import { UserAvatar } from "@homarr/ui"; | ||
| import { UserAvatar, UserProps } from "@homarr/ui"; | ||
|
|
||
| interface UserAvatarProps { | ||
| interface CurrentUserAvatarProps { | ||
| size: MantineSize; | ||
| } | ||
|
|
||
| export const CurrentUserAvatar = async ({ size }: UserAvatarProps) => { | ||
| export const CurrentUserAvatar = async ({ size }: CurrentUserAvatarProps) => { | ||
| const currentSession = await auth(); | ||
|
|
||
| const user = { | ||
| const user: UserProps = { | ||
| name: currentSession?.user.name ?? null, | ||
| image: currentSession?.user.image ?? null, | ||
| email: currentSession?.user.email ?? null, | ||
| }; | ||
|
|
||
| if (!user.image && !user.email && user.name) user.image = null; | ||
|
|
||
| return <UserAvatar user={user} size={size} />; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,9 +1,13 @@ | ||||||
| "use client"; | ||||||
|
|
||||||
| import type { AvatarProps } from "@mantine/core"; | ||||||
| import { Avatar } from "@mantine/core"; | ||||||
| import { createHash } from "crypto"; | ||||||
|
||||||
|
|
||||||
| export interface UserProps { | ||||||
| name: string | null; | ||||||
| image: string | null; | ||||||
| email?: string | null; | ||||||
| } | ||||||
|
|
||||||
| interface UserAvatarProps { | ||||||
|
|
@@ -13,9 +17,15 @@ interface UserAvatarProps { | |||||
|
|
||||||
| export const UserAvatar = ({ user, size }: UserAvatarProps) => { | ||||||
| if (!user?.name) return <Avatar size={size} />; | ||||||
|
|
||||||
| if (user.image) { | ||||||
| return <Avatar src={user.image} alt={user.name} size={size} />; | ||||||
| } | ||||||
|
|
||||||
| if (user.email) { | ||||||
| const emailHash = createHash("md5").update(user.email.trim().toLowerCase()).digest("hex"); | ||||||
| return <Avatar src={`https://seccdn.libravatar.org/avatar/${emailHash}?d=404`} alt={user.name} size={size} />; | ||||||
|
||||||
| return <Avatar src={`https://seccdn.libravatar.org/avatar/${emailHash}?d=404`} alt={user.name} size={size} />; | |
| return <Avatar src={`https://seccdn.libravatar.org/avatar/${emailHash}?d=blank`} alt={user.name} size={size} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to check if the usage of crypto actually works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for this? Can you explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's redundant because of
?? nullinsideconst user:.I can remove that part yeah