+
{children}
diff --git a/apps/dashboard/src/app/(auth)/register/[[...register]]/page.tsx b/apps/dashboard/src/app/(auth)/register/[[...register]]/page.tsx
index 0bb2fa30..c19dfc66 100644
--- a/apps/dashboard/src/app/(auth)/register/[[...register]]/page.tsx
+++ b/apps/dashboard/src/app/(auth)/register/[[...register]]/page.tsx
@@ -3,7 +3,7 @@ import { SignUp } from '@clerk/nextjs';
export default function Page() {
return (
-
+
);
}
diff --git a/apps/dashboard/src/app/(onboarding)/skip-onboarding.tsx b/apps/dashboard/src/app/(onboarding)/skip-onboarding.tsx
index 2df5162e..cc925789 100644
--- a/apps/dashboard/src/app/(onboarding)/skip-onboarding.tsx
+++ b/apps/dashboard/src/app/(onboarding)/skip-onboarding.tsx
@@ -1,20 +1,44 @@
'use client';
+import { useEffect } from 'react';
+import { showConfirm } from '@/modals';
+import { api } from '@/trpc/client';
+import { useAuth } from '@clerk/nextjs';
import { ChevronLastIcon } from 'lucide-react';
-import Link from 'next/link';
-import { usePathname } from 'next/navigation';
+import { usePathname, useRouter } from 'next/navigation';
const SkipOnboarding = () => {
+ const router = useRouter();
const pathname = usePathname();
+ const res = api.onboarding.skipOnboardingCheck.useQuery();
+ const auth = useAuth();
+ useEffect(() => {
+ res.refetch();
+ }, [pathname]);
+
+ console.log(res.data);
+
if (!pathname.startsWith('/onboarding')) return null;
return (
-
{
+ if (res.data?.canSkip && res.data?.url) {
+ router.push(res.data.url);
+ } else {
+ showConfirm({
+ title: 'Skip onboarding?',
+ text: 'Are you sure you want to skip onboarding? Since you do not have any projects, you will be logged out.',
+ onConfirm() {
+ auth.signOut();
+ },
+ });
+ }
+ }}
className="flex items-center gap-2 text-sm text-muted-foreground"
>
Skip onboarding
-
+
);
};
diff --git a/packages/trpc/src/routers/onboarding.ts b/packages/trpc/src/routers/onboarding.ts
index 8504cc78..93aba90a 100644
--- a/packages/trpc/src/routers/onboarding.ts
+++ b/packages/trpc/src/routers/onboarding.ts
@@ -2,7 +2,14 @@ import crypto from 'crypto';
import type { z } from 'zod';
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
-import { db, getId, getOrganizationBySlug, getUserById } from '@openpanel/db';
+import {
+ db,
+ getCurrentOrganizations,
+ getCurrentProjects,
+ getId,
+ getOrganizationBySlug,
+ getUserById,
+} from '@openpanel/db';
import type { ProjectType } from '@openpanel/db';
import { zOnboardingProject } from '@openpanel/validation';
@@ -30,6 +37,35 @@ async function createOrGetOrganization(
}
export const onboardingRouter = createTRPCRouter({
+ skipOnboardingCheck: protectedProcedure.query(async ({ ctx }) => {
+ const members = await db.member.findMany({
+ where: {
+ userId: ctx.session.userId,
+ },
+ });
+
+ if (members.length > 0) {
+ return {
+ canSkip: true,
+ url: `/${members[0]?.organizationId}`,
+ };
+ }
+
+ const projectAccess = await db.projectAccess.findMany({
+ where: {
+ userId: ctx.session.userId,
+ },
+ });
+
+ if (projectAccess.length > 0) {
+ return {
+ canSkip: true,
+ url: `/${projectAccess[0]?.organizationId}/${projectAccess[0]?.projectId}`,
+ };
+ }
+
+ return { canSkip: false, url: null };
+ }),
project: protectedProcedure
.input(zOnboardingProject)
.mutation(async ({ input, ctx }) => {