Skip to content

Commit

Permalink
fix(dashboard): set full session with token auth (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiiBz authored Jun 14, 2023
1 parent 5fcb1ec commit f97aa7e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-ants-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lagon/dashboard': patch
---

Properly set session information when authenticating via a token
42 changes: 32 additions & 10 deletions packages/dashboard/pages/api/trpc/[trpc].ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const createContext = async ({
select: {
id: true,
email: true,
name: true,
currentOrganizationId: true,
},
},
Expand All @@ -55,25 +56,46 @@ const createContext = async ({
});
}

// We shouldn't use anything other than ID in the session when
// authenticating with tokens
const organization = await prisma.organization.findFirst({
where: {
id: token.user.currentOrganizationId ?? '',
},
select: {
id: true,
name: true,
description: true,
stripeSubscriptionId: true,
stripePriceId: true,
stripeCustomerId: true,
stripeCurrentPeriodEnd: true,
createdAt: true,
},
});

Sentry.setUser({
id: token.user.id,
username: token.user.name ?? 'Unknown',
email: token.user.email ?? 'Unknown',
});

return {
req,
res,
session: {
user: {
id: token.user.id,
name: '',
name: token.user.name ?? '',
email: token.user.email ?? '',
},
organization: {
id: token.user.currentOrganizationId ?? '',
name: '',
stripePriceId: null,
stripeCustomerId: null,
stripeSubscriptionId: null,
stripeCurrentPeriodEnd: null,
createdAt: new Date(),
id: organization?.id ?? '',
name: organization?.name ?? '',
description: organization?.description ?? '',
stripeSubscriptionId: organization?.stripeSubscriptionId ?? '',
stripePriceId: organization?.stripePriceId ?? '',
stripeCustomerId: organization?.stripeCustomerId ?? '',
stripeCurrentPeriodEnd: organization?.stripeCurrentPeriodEnd ?? new Date(),
createdAt: organization?.createdAt ?? new Date(),
},
expires: '',
},
Expand Down

1 comment on commit f97aa7e

@vercel
Copy link

@vercel vercel bot commented on f97aa7e Jun 14, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

dashboard – ./packages/dashboard

dashboard-lagon.vercel.app
dashboard-git-main-lagon.vercel.app
dash.lagon.app

Please sign in to comment.