Spaces:
Running
Running
expand to desktop
Browse files- app/auth/callback/page.tsx +0 -5
- hooks/useUser.ts +1 -11
app/auth/callback/page.tsx
CHANGED
@@ -20,26 +20,21 @@ export default function AuthCallback({
|
|
20 |
|
21 |
useMount(async () => {
|
22 |
if (code) {
|
23 |
-
// Check if this is a popup window opened for authentication
|
24 |
-
// by checking if window.opener exists or if we can communicate with parent
|
25 |
const isPopup = window.opener || window.parent !== window;
|
26 |
setIsPopupAuth(isPopup);
|
27 |
|
28 |
if (isPopup) {
|
29 |
-
// Broadcast the auth code to the parent window/iframe
|
30 |
postMessage({
|
31 |
type: "user-oauth",
|
32 |
code: code,
|
33 |
});
|
34 |
|
35 |
-
// Close this popup/tab after a short delay
|
36 |
setTimeout(() => {
|
37 |
if (window.opener) {
|
38 |
window.close();
|
39 |
}
|
40 |
}, 1000);
|
41 |
} else {
|
42 |
-
// Normal flow for direct navigation to callback
|
43 |
await loginFromCode(code);
|
44 |
}
|
45 |
}
|
|
|
20 |
|
21 |
useMount(async () => {
|
22 |
if (code) {
|
|
|
|
|
23 |
const isPopup = window.opener || window.parent !== window;
|
24 |
setIsPopupAuth(isPopup);
|
25 |
|
26 |
if (isPopup) {
|
|
|
27 |
postMessage({
|
28 |
type: "user-oauth",
|
29 |
code: code,
|
30 |
});
|
31 |
|
|
|
32 |
setTimeout(() => {
|
33 |
if (window.opener) {
|
34 |
window.close();
|
35 |
}
|
36 |
}, 1000);
|
37 |
} else {
|
|
|
38 |
await loginFromCode(code);
|
39 |
}
|
40 |
}
|
hooks/useUser.ts
CHANGED
@@ -61,25 +61,20 @@ export const useUser = (initialData?: {
|
|
61 |
const openLoginWindow = async () => {
|
62 |
setCurrentRoute(window.location.pathname);
|
63 |
|
64 |
-
|
65 |
-
if (isInIframe() && isMobileDevice()) {
|
66 |
try {
|
67 |
-
// Get the login URL from the server
|
68 |
const response = await api.get("/auth/login-url");
|
69 |
const { loginUrl } = response.data;
|
70 |
|
71 |
-
// Open in new tab for mobile iframe users
|
72 |
window.open(loginUrl, "_blank", "noopener,noreferrer");
|
73 |
|
74 |
toast.info("Login opened in new tab. Please complete authentication and return to this page.");
|
75 |
return;
|
76 |
} catch (error) {
|
77 |
console.error("Failed to open login in new tab:", error);
|
78 |
-
// Fall back to normal flow if opening new tab fails
|
79 |
}
|
80 |
}
|
81 |
|
82 |
-
// Normal login flow for non-iframe or non-mobile users
|
83 |
return router.push("/auth");
|
84 |
};
|
85 |
|
@@ -90,8 +85,6 @@ export const useUser = (initialData?: {
|
|
90 |
.post("/auth", { code })
|
91 |
.then(async (res: any) => {
|
92 |
if (res.data) {
|
93 |
-
// Cookie is now set server-side with proper iframe attributes
|
94 |
-
// Also store fallback data for iframe contexts
|
95 |
if (res.data.useLocalStorageFallback) {
|
96 |
storeAuthDataFallback(res.data.access_token, res.data.user);
|
97 |
}
|
@@ -119,9 +112,7 @@ export const useUser = (initialData?: {
|
|
119 |
|
120 |
const logout = async () => {
|
121 |
try {
|
122 |
-
// Call server endpoint to clear the HTTP-only cookie
|
123 |
await api.post("/auth/logout");
|
124 |
-
// Clear fallback storage
|
125 |
clearAuthDataFallback();
|
126 |
removeCurrentRoute();
|
127 |
client.setQueryData(["user.me"], { user: null, errCode: null });
|
@@ -131,7 +122,6 @@ export const useUser = (initialData?: {
|
|
131 |
window.location.reload();
|
132 |
} catch (error) {
|
133 |
console.error("Logout error:", error);
|
134 |
-
// Even if server call fails, clear client state
|
135 |
clearAuthDataFallback();
|
136 |
removeCurrentRoute();
|
137 |
client.setQueryData(["user.me"], { user: null, errCode: null });
|
|
|
61 |
const openLoginWindow = async () => {
|
62 |
setCurrentRoute(window.location.pathname);
|
63 |
|
64 |
+
if (isInIframe()) {
|
|
|
65 |
try {
|
|
|
66 |
const response = await api.get("/auth/login-url");
|
67 |
const { loginUrl } = response.data;
|
68 |
|
|
|
69 |
window.open(loginUrl, "_blank", "noopener,noreferrer");
|
70 |
|
71 |
toast.info("Login opened in new tab. Please complete authentication and return to this page.");
|
72 |
return;
|
73 |
} catch (error) {
|
74 |
console.error("Failed to open login in new tab:", error);
|
|
|
75 |
}
|
76 |
}
|
77 |
|
|
|
78 |
return router.push("/auth");
|
79 |
};
|
80 |
|
|
|
85 |
.post("/auth", { code })
|
86 |
.then(async (res: any) => {
|
87 |
if (res.data) {
|
|
|
|
|
88 |
if (res.data.useLocalStorageFallback) {
|
89 |
storeAuthDataFallback(res.data.access_token, res.data.user);
|
90 |
}
|
|
|
112 |
|
113 |
const logout = async () => {
|
114 |
try {
|
|
|
115 |
await api.post("/auth/logout");
|
|
|
116 |
clearAuthDataFallback();
|
117 |
removeCurrentRoute();
|
118 |
client.setQueryData(["user.me"], { user: null, errCode: null });
|
|
|
122 |
window.location.reload();
|
123 |
} catch (error) {
|
124 |
console.error("Logout error:", error);
|
|
|
125 |
clearAuthDataFallback();
|
126 |
removeCurrentRoute();
|
127 |
client.setQueryData(["user.me"], { user: null, errCode: null });
|