Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions liveblocks.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ declare global {
// Example properties, for useSelf, useUser, useOthers, etc.
name: string;
avatar: string;
color?: string;
};
};

Expand Down
14 changes: 12 additions & 2 deletions src/app/api/auth/liveblocks/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,21 @@ export async function POST(req: Request) {
if (!isOwner && !isOrgMember)
return new Response("Unauthorized", { status: 401 });

const name =
user.fullName ?? user.primaryEmailAddress?.emailAddress ?? "Anonymous";

const nameToNumber = name.split("").reduce((acc, char) => {
return acc + char.charCodeAt(0);
}, 0);

const hue = Math.abs(nameToNumber) % 360;
const color = `hsl(${hue}, 80%, 60%)`;

const session = liveblocks.prepareSession(user.id, {
userInfo: {
name:
user.fullName ?? user.primaryEmailAddress?.emailAddress ?? "Anonymous",
name,
avatar: user.imageUrl,
color,
},
});

Expand Down