Skip to content

Commit 64d87b4

Browse files
committed
fix: smoother onboarding
1 parent eb4eea3 commit 64d87b4

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

apps/dashboard/app/(auth)/login/page.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ function LoginPage() {
2828
const [lastUsed, setLastUsed] = useState<string | null>(null);
2929

3030
const defaultCallbackUrl = searchParams.get('callback') || '/websites';
31-
const prefilledEmail = searchParams.get('email');
3231

3332
useEffect(() => {
3433
setLastUsed(localStorage.getItem('lastUsedLogin'));
35-
if (prefilledEmail) {
36-
setEmail(prefilledEmail);
37-
}
38-
}, [prefilledEmail]);
34+
}, []);
3935

4036
const handlePostAuthCallback = () => {
4137
const callbackUrl = searchParams.get('callback');

apps/dashboard/app/(auth)/register/page.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ function RegisterPageContent() {
3434
const searchParams = useSearchParams();
3535
const selectedPlan = searchParams.get('plan');
3636
const callbackUrl = searchParams.get('callback');
37-
const prefilledEmail = searchParams.get('email');
38-
const prefilledName = searchParams.get('name');
3937
const [isLoading, setIsLoading] = useState(false);
4038
const [formData, setFormData] = useState({
41-
name: prefilledName || '',
42-
email: prefilledEmail || '',
39+
name: '',
40+
email: '',
4341
password: '',
4442
confirmPassword: '',
4543
});
@@ -569,7 +567,7 @@ function RegisterPageContent() {
569567
className="font-medium text-primary hover:text-primary/80"
570568
href={
571569
callbackUrl
572-
? `/login?email=${encodeURIComponent(formData.email)}&callback=${encodeURIComponent(callbackUrl)}`
570+
? `/login?callback=${encodeURIComponent(callbackUrl)}`
573571
: '/login'
574572
}
575573
>

apps/dashboard/app/api/integrations/vercel/callback/route.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { randomUUID } from 'node:crypto';
2-
import { account, and, db, eq, user } from '@databuddy/db';
2+
import { auth } from '@databuddy/auth';
3+
import { account, and, db, eq } from '@databuddy/db';
4+
import { headers } from 'next/headers';
35
import { type NextRequest, NextResponse } from 'next/server';
46

57
interface VercelTokenResponse {
@@ -29,6 +31,19 @@ export async function GET(request: NextRequest) {
2931
);
3032
}
3133

34+
// Check if user is authenticated
35+
const session = await auth.api.getSession({ headers: await headers() });
36+
37+
// If no session, redirect to auth pages with the callback URL
38+
if (!session?.user) {
39+
const callbackUrl = new URL(request.url);
40+
const completeIntegrationUrl = `${process.env.BETTER_AUTH_URL}${callbackUrl.pathname}${callbackUrl.search}`;
41+
42+
return NextResponse.redirect(
43+
`${process.env.BETTER_AUTH_URL}/register?callback=${encodeURIComponent(completeIntegrationUrl)}`
44+
);
45+
}
46+
3247
const redirectUri = `${process.env.BETTER_AUTH_URL}/api/integrations/vercel/callback`;
3348

3449
const tokenResponse = await fetch(
@@ -76,21 +91,7 @@ export async function GET(request: NextRequest) {
7691
);
7792
}
7893

79-
const existingUser = await db.query.user.findFirst({
80-
where: eq(user.email, userInfo.email),
81-
});
82-
83-
if (!existingUser) {
84-
// Create the callback URL that will complete the integration after auth
85-
const callbackUrl = new URL(request.url);
86-
const completeIntegrationUrl = `${process.env.BETTER_AUTH_URL}${callbackUrl.pathname}${callbackUrl.search}`;
87-
88-
return NextResponse.redirect(
89-
`${process.env.BETTER_AUTH_URL}/register?email=${encodeURIComponent(userInfo.email)}&name=${encodeURIComponent(userInfo.name || '')}&callback=${encodeURIComponent(completeIntegrationUrl)}`
90-
);
91-
}
92-
93-
const userId = existingUser.id;
94+
const userId = session.user.id;
9495

9596
const existingAccount = await db.query.account.findFirst({
9697
where: and(eq(account.userId, userId), eq(account.providerId, 'vercel')),

0 commit comments

Comments
 (0)