Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(support): create plain customer for users with missing name (#11734)

Hassieb Pakzad68778ee4bc81
diff --git a/web/src/features/support-chat/trpc/plainRouter.ts b/web/src/features/support-chat/trpc/plainRouter.ts
index 9d349d64ad..c7444b1d7e 100644
--- a/web/src/features/support-chat/trpc/plainRouter.ts
+++ b/web/src/features/support-chat/trpc/plainRouter.ts
@@ -112,7 +112,7 @@ export const plainRouter = createTRPCRouter({
.input(PrepareAttachmentUploadsInput)
.mutation(async ({ ctx, input }) => {
const email = ctx.session.user.email;
- const fullName = ctx.session.user.name ?? undefined;
+ const fullName = getFullName(ctx.session.user);
if (!email) {
throw new TRPCError({
code: "BAD_REQUEST",
@@ -147,7 +147,7 @@ export const plainRouter = createTRPCRouter({
.input(CreateSupportThreadInput)
.mutation(async ({ ctx, input }) => {
const email = ctx.session.user.email;
- const fullName = ctx.session.user.name ?? undefined;
+ const fullName = getFullName(ctx.session.user);
if (!email) {
throw new TRPCError({
code: "BAD_REQUEST",
@@ -322,3 +322,21 @@ export const plainRouter = createTRPCRouter({
};
}),
});
+
+function getFullName(user: {
+ name?: string | null;
+ email?: string | null;
+ id: string;
+}): string {
+ const { name, email } = user ?? {};
+
+ if (name?.trim()) return name;
+
+ if (email) {
+ const emailUserName = email.split("@")[0];
+
+ if (emailUserName) return emailUserName;
+ }
+
+ return user?.id.slice(0, 8) ?? "Anonymous";
+}