Skip to content

fixing jwt signer regression #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2025
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
4 changes: 2 additions & 2 deletions apps/web/app/dashboard/(authenticated)/connect/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ export default function MagicLinkPage() {
onSubmit={({formData: values}) => {
createMagicLink.mutate(values, {
onSuccess: async (data) => {
await copyToClipboard(data.url)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider wrapping the call to copyToClipboard in a try/catch block to ensure that a clipboard failure doesn't prevent subsequent redirection and toast display. This is especially useful since in isMainPreview mode, a failure here might block the intended redirection.


if (isMainPreview) {
window.location.href = data.url
} else {
await copyToClipboard(data.url)
}
toast({
title: 'Magic link copied to clipboard',
Expand Down
65 changes: 35 additions & 30 deletions packages/engine-backend/router/customerRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,39 +197,44 @@ export const customerRouter = trpc.router({
})
.input(customerRouterSchema.createMagicLink.input)
.output(z.object({url: z.string()}))
.mutation(({input: {customerId, validityInSeconds, ...params}, ctx}) => {
const token = ctx.jwt.signViewer(asCustomer(ctx.viewer, {customerId}), {
validityInSeconds,
})
// Mapping integrationIds and connectorNames to a clean format removing any extra spaces
// and ensuring they are prefixed with int_ if they are in the format of connectorName_integrationId.
const mappedParams = {
...params,
token,
integrationIds: params.integrationIds?.split(',').map((id) => {
const trimmedId = id.trim()
.mutation(
async ({input: {customerId, validityInSeconds, ...params}, ctx}) => {
const token = await ctx.jwt.signViewer(
asCustomer(ctx.viewer, {customerId}),
{
validityInSeconds,
},
)
// Mapping integrationIds and connectorNames to a clean format removing any extra spaces
// and ensuring they are prefixed with int_ if they are in the format of connectorName_integrationId.
const mappedParams = {
...params,
token,
integrationIds: params.integrationIds?.split(',').map((id) => {
const trimmedId = id.trim()

return trimmedId.includes('_') &&
trimmedId.split('_').length === 2 &&
!trimmedId.startsWith('int_')
? `int_${trimmedId}`
: trimmedId
}),
connectorNames: params.connectorNames
?.split(',')
.map((name) => name.trim()),
theme: params.theme ?? 'light',
view: params.view ?? 'add',
}
return trimmedId.includes('_') &&
trimmedId.split('_').length === 2 &&
!trimmedId.startsWith('int_')
? `int_${trimmedId}`
: trimmedId
}),
connectorNames: params.connectorNames
?.split(',')
.map((name) => name.trim()),
theme: params.theme ?? 'light',
view: params.view ?? 'add',
}

const url = new URL('/connect/portal', ctx.apiUrl) // `/` will start from the root hostname itself
for (const [key, value] of Object.entries(mappedParams)) {
if (value) {
url.searchParams.set(key, `${value ?? ''}`)
const url = new URL('/connect/portal', ctx.apiUrl) // `/` will start from the root hostname itself
for (const [key, value] of Object.entries(mappedParams)) {
if (value) {
url.searchParams.set(key, `${value ?? ''}`)
}
}
}
return {url: url.toString()}
}),
return {url: url.toString()}
},
),
createFilePickerLink: protectedProcedure
.meta({
openapi: {
Expand Down