| 1 | import type { AvatarConfig } from "@better-auth-ui/core"; |
| 2 | |
| 3 | import { API_URL } |
| 4 | |
| 5 | /** |
| 6 | * Avatar storage backed by the API's S3 bucket. |
| 7 | * |
| 8 | * Better Auth UI otherwise stores a base64 data URL in `user.image`, which then rides along in every session payload. |
| 9 | */ |
| 10 | export const avatar: |
| 11 | // PNG, not WebP: avatars are drawn into the OG images, and `next/og` cannot decode WebP. |
| 12 | extension: "png", |
| 13 | |
| 14 | upload: (file) |
| 15 | delete: () => |
| 16 | }; |
| 17 | |
| 18 | /** Uploads raw image bytes to an API path that stores a picture, and returns the URL it is served from. */ |
| 19 | export async function putImage |
| 20 | const response = |
| 21 | method: "PUT", |
| 22 | credentials: "include", |
| 23 | headers: { "Content-Type": |
| 24 | body: file, |
| 25 | }); |
| 26 | |
| 27 | if (!response.ok |
| 28 | |
| 29 | const { url |
| 30 | return url; |
| 31 | } |
| 32 | |
| 33 | export async function deleteImage |
| 34 | const response = |
| 35 | method: "DELETE", |
| 36 | credentials: "include", |
| 37 | }); |
| 38 | |
| 39 | if (!response.ok |
| 40 | } |
| 41 | |
| 42 | async function errorMessage( |
| 43 | const body = |
| 44 | message?: string |
| 45 | } | null; |
| 46 | |
| 47 | return body?.message |
| 48 | } |