Skip to content

Commit

Permalink
hotfix for usernames on sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
berekuk committed Sep 14, 2023
1 parent a4c6f69 commit 334aa2f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/hub/src/app/api/auth/[...nextauth]/authOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ function buildAuthOptions() {
adapter: PrismaAdapter(prisma),
providers,
callbacks: {
session({ session, user }) {
session.user.username = user.username;
async session({ session, user }) {
// is there a way to ask PrismaAdapter to select it by default?
const fullUser = await prisma.user.findUnique({
where: { id: user.id },
include: { asOwner: true },
});
const username = fullUser?.asOwner?.slug;
if (username) {
session.user.username = username;
}
return session;
},
},
Expand Down

1 comment on commit 334aa2f

@vercel
Copy link

@vercel vercel bot commented on 334aa2f Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.