Skip to content

Commit b88246e

Browse files
authored
Merge pull request joincalldotco#156 from stagioo/fix/redirection-issues
Fix/redirection issues
2 parents 91ab6c7 + c0ca8ba commit b88246e

File tree

5 files changed

+71
-15
lines changed

5 files changed

+71
-15
lines changed

apps/web/app/(app)/layout.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const AppLayout = async ({ children }: { children: React.ReactNode }) => {
99
headers: await headers(),
1010
});
1111

12-
// if (!session) redirect("/login");
13-
if (!session) return null;
12+
if (!session) redirect("/login");
1413
return <SessionProvider value={session}>{children}</SessionProvider>;
1514
};
1615

apps/web/components/app/section/_components/create-team-modal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function CreateTeamModal({ onClose, onTeamCreated }: {
3838

3939
const fetchContacts = async () => {
4040
try {
41-
const res = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/contacts`, {
41+
const res = await fetch(`${process.env.BACKEND_URL}/api/contacts`, {
4242
credentials: "include",
4343
});
4444
if (res.ok) {
@@ -87,7 +87,7 @@ export function CreateTeamModal({ onClose, onTeamCreated }: {
8787
members: selectedMembers,
8888
};
8989

90-
const res = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/teams/create`, {
90+
const res = await fetch(`${process.env.BACKEND_URL}/api/teams/create`, {
9191
method: "POST",
9292
headers: {
9393
"Content-Type": "application/json",

apps/web/components/app/section/team-section.tsx

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,55 @@ export const TeamSection = () => {
5050
},
5151
});
5252

53-
const { mutate: createCall, isPending: createCallPending } = useMutation({
54-
mutationFn: CALLS_QUERY.createCall,
55-
onSuccess: (data) => {
56-
toast.success("Call created successfully", {
57-
description: "Redirecting to call...",
53+
54+
// Prevent hydration mismatch
55+
useEffect(() => {
56+
setMounted(true);
57+
}, []);
58+
59+
const startTeamMeeting = async (team: Team) => {
60+
try {
61+
setStartingMeeting(team.id);
62+
const res = await fetch(`${process.env.BACKEND_URL}/api/calls/create`, {
63+
method: "POST",
64+
headers: { "Content-Type": "application/json" },
65+
credentials: "include",
66+
body: JSON.stringify({
67+
name: `${team.name} Meeting`,
68+
members: team.members.map((m) => m.email),
69+
teamId: team.id,
70+
}),
5871
});
5972
router.push(`/app/call/${data.callId}`);
60-
},
61-
onError: (error) => {
62-
toast.error("Failed to create call");
63-
},
64-
});
73+
74+
} catch (err) {
75+
alert("Network error starting meeting");
76+
} finally {
77+
setStartingMeeting(null);
78+
}
79+
};
80+
81+
// Fetch contacts only when modal opens
82+
useEffect(() => {
83+
if (addUsersOpen) {
84+
fetch(`${process.env.BACKEND_URL}/api/contacts`, { credentials: "include" })
85+
.then(res => res.json())
86+
.then(data => setContacts(data.contacts || []));
87+
}
88+
}, [addUsersOpen]);
89+
90+
const handleAddUsers = async () => {
91+
if (!addUsersOpen) return;
92+
setAddLoading(true);
93+
setAddError(null);
94+
try {
95+
const res = await fetch(`${process.env.BACKEND_URL}/api/teams/${addUsersOpen}/add-members`, {
96+
method: "POST",
97+
headers: { "Content-Type": "application/json" },
98+
credentials: "include",
99+
body: JSON.stringify({ emails: selectedContacts }),
100+
});
101+
65102

66103
const startTeamMeeting = async (team: Team) => {
67104
createCall({

packages/auth/src/auth-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createAuthClient } from "better-auth/react";
22

33
export const authClient = createAuthClient({
4-
baseURL: process.env.BACKEND_URL,
4+
baseURL: process.env.NEXT_PUBLIC_BACKEND_URL || "http://localhost:1284",
55
});

packages/auth/src/auth.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ export const auth = betterAuth({
2929

3030
trustedOrigins: [process.env.FRONTEND_URL, process.env.BACKEND_URL],
3131

32+
// Add cookie configuration for cross-domain support
33+
session: {
34+
cookieCache: {
35+
enabled: true,
36+
maxAge: 60 * 60 * 24 * 7, // 7 days
37+
},
38+
},
39+
40+
// Cookie configuration for cross-domain
41+
cookies: {
42+
sessionToken: {
43+
name: "better-auth.session-token",
44+
httpOnly: true,
45+
secure: process.env.NODE_ENV === "production",
46+
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",
47+
domain: process.env.NODE_ENV === "production" ? ".joincall.co" : undefined,
48+
maxAge: 60 * 60 * 24 * 7, // 7 days
49+
},
50+
},
51+
3252
emailAndPassword: {
3353
enabled: true,
3454
autoSignIn: true,

0 commit comments

Comments
 (0)