Supabase Avatar URL Resolver (utils/avatar.ts)

bolt.diy_V2.0 · auth, Auth / Identity, supabase, avatar, oauth, react, utils

Generates a user avatar URL from Supabase user data, handling multiple OAuth providers and optional proxy fallback.

// Source: https://github.com/mperkins0155/bolt.diy_V2.0 | License: MIT | Copyright 2024 StackBlitz, Inc
// Provided via justclaw.it.com; keep this notice with the code.
import type { User } from '@supabase/supabase-js';
import { BRAND_COLORS } from '~/utils/brand-colors';

/**
 * Get avatar URL from Supabase user data, trying multiple sources.
 * Different OAuth providers store avatar data in different places.
 */
export function getAvatarUrl(
  user: User,
  fallbackColor: string = BRAND_COLORS.AVATAR.FALLBACK,
  useProxy: boolean = false,
): string {
  let avatarUrl: string | null = null;

  // try user_metadata first (GitHub usually stores it here)
  if (user.user_metadata?.avatar_url) {
    avatarUrl = user.user_metadata.avatar_url;
  }
  // try identities array (Google might store it

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key