import { ManagementClient } from "auth0"

export async function userNickname(userId: string): Promise<string | null> {
  const m = new ManagementClient({
    domain: process.env.AUTH0_ISSUER_BASE_URL ?? "",
    clientId: process.env.AUTH0_MANAGEMENT_CLIENT_ID ?? "",
    clientSecret: process.env.AUTH0_MANAGEMENT_CLIENT_SECRET ?? "",
  })
  try {
    const user = await m.users.get({ id: userId, fields: "nickname" })
    return user.data?.nickname
  } catch (error) {
    console.log("Error getting user nickname:", error)
    return null
  }
}
