Skip to content
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
17 changes: 14 additions & 3 deletions src/app/profile/create/ProfileCreationHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { useRouter } from 'next/navigation';
import { useRouter, useSearchParams } from 'next/navigation';
import { useEffect, useState } from 'react';

import {
Expand Down Expand Up @@ -33,6 +33,7 @@ export function ProfileCreationHandler({
const [loadingUser, setLoadingUser] = useState(false);
const [userId, setUserId] = useState<string | undefined>(userIdProp);
const [user, setUser] = useState<typeof userProp>(userProp);
const searchParams = useSearchParams();

// Ensure we have the current user and id; redirect if unauthorized
useEffect(() => {
Expand Down Expand Up @@ -135,8 +136,18 @@ export function ProfileCreationHandler({
// Clear any draft data
localStorage.removeItem('profile-wizard-draft');

// Redirect to lobby with welcome message
router.push('/stacks?welcome=true');
// Redirect to intended destination if provided, otherwise to lobby
const returnTo = searchParams?.get('returnTo');
if (returnTo) {
try {
const decoded = decodeURIComponent(returnTo);
router.push(decoded);
} catch {
router.push('/stacks?welcome=true');
}
} else {
router.push('/stacks?welcome=true');
}
router.refresh(); // Refresh to update session data
} catch (error) {
alert(
Expand Down
6 changes: 4 additions & 2 deletions src/components/CollectionDetailClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,10 @@ export function CollectionDetailClient({
storedInviteToken
);
}
const returnTo = encodeURIComponent(`/collection/${collectionId}`);
window.location.href = `/api/auth/signin?callbackUrl=${returnTo}`;
// Always route through our smart auth callback so invite consumption
// and profile completion logic can run before landing on the library
const callback = encodeURIComponent('/auth/callback');
window.location.href = `/auth/signin?callbackUrl=${callback}`;
} else {
const data = await res.json().catch(() => ({}));
console.error('[CollectionDetailClient] join failed', {
Expand Down