fix onboarding

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-03-13 11:47:27 +01:00
parent 996702437f
commit cfa1d9ab46
3 changed files with 12 additions and 6 deletions

View File

@@ -3,7 +3,7 @@ import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc';
import { db } from '@/server/db'; import { db } from '@/server/db';
import { z } from 'zod'; import { z } from 'zod';
import { hashPassword } from '@openpanel/common'; import { hashPassword, stripTrailingSlash } from '@openpanel/common';
export const clientRouter = createTRPCRouter({ export const clientRouter = createTRPCRouter({
list: protectedProcedure list: protectedProcedure
@@ -71,7 +71,7 @@ export const clientRouter = createTRPCRouter({
project_id: input.projectId, project_id: input.projectId,
name: input.name, name: input.name,
secret: input.cors ? null : await hashPassword(secret), secret: input.cors ? null : await hashPassword(secret),
cors: input.cors || undefined, cors: input.cors ? stripTrailingSlash(input.cors) : '*',
}, },
}); });

View File

@@ -3,7 +3,7 @@ import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc';
import { clerkClient } from '@clerk/nextjs'; import { clerkClient } from '@clerk/nextjs';
import { z } from 'zod'; import { z } from 'zod';
import { hashPassword } from '@openpanel/common'; import { hashPassword, stripTrailingSlash } from '@openpanel/common';
import { db } from '@openpanel/db'; import { db } from '@openpanel/db';
export const onboardingRouter = createTRPCRouter({ export const onboardingRouter = createTRPCRouter({
@@ -35,7 +35,7 @@ export const onboardingRouter = createTRPCRouter({
name: `${project.name} Client`, name: `${project.name} Client`,
organization_slug: org.slug, organization_slug: org.slug,
project_id: project.id, project_id: project.id,
cors: input.cors ?? '*', cors: input.cors ? stripTrailingSlash(input.cors) : '*',
secret: input.cors ? null : await hashPassword(secret), secret: input.cors ? null : await hashPassword(secret),
}, },
}); });
@@ -43,7 +43,7 @@ export const onboardingRouter = createTRPCRouter({
return { return {
client: { client: {
...client, ...client,
secret, secret: input.cors ? null : secret,
}, },
project, project,
organization: org, organization: org,

View File

@@ -60,7 +60,6 @@ import {
setProfile, setProfile,
setProfileId, setProfileId,
trackEvent, trackEvent,
trackScreenView,
} from '@openpanel/nextjs'; } from '@openpanel/nextjs';
// Sends an event with payload foo: bar // Sends an event with payload foo: bar
@@ -189,6 +188,13 @@ clear();
If you want to track server-side events, you should create an instance of our Javascript SDK. It's exported from `@openpanel/nextjs` If you want to track server-side events, you should create an instance of our Javascript SDK. It's exported from `@openpanel/nextjs`
<Callout>
When using server events it's important to create a new client (with a secret). Since it's backend we cannot authorize the request with cors headers.
`Openpanel Dashboard -> Setting -> Clients -> Create client`
</Callout>
```typescript ```typescript
import { OpenpanelSdk } from '@openpanel/nextjs'; import { OpenpanelSdk } from '@openpanel/nextjs';