How to know if a public url doesn't exist?

Im trying to fetch a user's avatar from the public bucket.

I wish to know whether the URL is valid or not so that I could use a default URL in case url is invalid. How to achieve this?

export const fetchAvatarUrl = async (userId: string) => {
    const { data } = await supabase.storage
    .from('profile_pictures')
    .getPublicUrl(`${userId}`)

    console.log("avatar url:", data.publicUrl)
}
Was this page helpful?