Skip to content

Commit 5233ad5

Browse files
committed
fix(login): require user click to open signin, fix auth init state
1 parent 6830b24 commit 5233ad5

2 files changed

Lines changed: 35 additions & 19 deletions

File tree

src/pages/Login.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ export default function Login() {
3434
// Always call hooks unconditionally - React Hooks must be called in the same order
3535
const stackApp = useStackApp();
3636
const app = HAS_STACK_KEYS ? stackApp : null;
37-
const { setAuth, setModelType, setLocalProxyValue } = useAuthStore();
37+
const {
38+
setAuth,
39+
setModelType,
40+
setLocalProxyValue,
41+
setInitState,
42+
setIsFirstLaunch,
43+
} = useAuthStore();
3844
const navigate = useNavigate();
3945
const location = useLocation();
4046
const { t } = useTranslation();
@@ -98,6 +104,9 @@ export default function Login() {
98104

99105
setAuth({ email: data.email, ...data });
100106
setLocalProxyValue(import.meta.env.VITE_USE_LOCAL_PROXY || null);
107+
setModelType('custom');
108+
setInitState('done');
109+
setIsFirstLaunch(false);
101110
navigate('/');
102111
} catch (error: any) {
103112
console.error('Auto login failed:', error);
@@ -272,17 +281,15 @@ export default function Login() {
272281
};
273282
}, []);
274283

275-
// Hybrid/app mode: get auth callback URL from Electron and open signin page
284+
// Hybrid/app mode: prepare auth callback URL on mount (don't auto-open browser)
276285
useEffect(() => {
277286
if (IS_LOCAL_MODE) return;
278287

279-
const openSignin = async () => {
288+
const prepareCallbackUrl = async () => {
280289
let cbUrl: string;
281290
if (import.meta.env.PROD) {
282-
// Production (packaged app): use eigent:// custom protocol
283291
cbUrl = 'eigent://auth/callback';
284292
} else {
285-
// Dev mode: use local HTTP server (eigent:// doesn't route to existing dev process)
286293
cbUrl = 'eigent://auth/callback';
287294
try {
288295
const url = await window.ipcRenderer?.invoke('get-auth-callback-url');
@@ -292,14 +299,9 @@ export default function Login() {
292299
}
293300
}
294301
setCallbackUrl(cbUrl);
295-
window.open(
296-
`https://www.eigent.ai/signin?callbackUrl=${encodeURIComponent(cbUrl)}`,
297-
'_blank',
298-
'noopener,noreferrer'
299-
);
300302
};
301303

302-
openSignin();
304+
prepareCallbackUrl();
303305
}, []);
304306

305307
// Render local mode: "Start Eigent" button only
@@ -341,17 +343,20 @@ export default function Login() {
341343
<div className="mb-4 text-heading-lg font-bold text-text-heading">
342344
{t('layout.login')}
343345
</div>
344-
<p className="mb-6 text-center text-label-md text-text-secondary">
345-
{t('layout.logging-in')}...
346-
</p>
346+
{isLoading && (
347+
<p className="mb-6 text-center text-label-md text-text-secondary">
348+
{t('layout.logging-in')}...
349+
</p>
350+
)}
347351
<Button
348-
onClick={() =>
352+
onClick={() => {
353+
setIsLoading(true);
349354
window.open(
350355
`https://www.eigent.ai/signin?callbackUrl=${encodeURIComponent(callbackUrl || 'eigent://auth/callback')}`,
351356
'_blank',
352357
'noopener,noreferrer'
353-
)
354-
}
358+
);
359+
}}
355360
size="lg"
356361
variant="primary"
357362
className="w-full rounded-full"

src/routers/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,16 @@ const ProtectedRoute = () => {
6464
initialized: false,
6565
});
6666

67-
const { token, localProxyValue, logout, setAuth, setLocalProxyValue } =
68-
useAuthStore();
67+
const {
68+
token,
69+
localProxyValue,
70+
logout,
71+
setAuth,
72+
setLocalProxyValue,
73+
setInitState,
74+
setIsFirstLaunch,
75+
setModelType,
76+
} = useAuthStore();
6977
useEffect(() => {
7078
// Check VITE_USE_LOCAL_PROXY value on app startup
7179
if (token) {
@@ -88,6 +96,9 @@ const ProtectedRoute = () => {
8896
if (data && data.token) {
8997
setAuth({ email: data.email, ...data });
9098
setLocalProxyValue(import.meta.env.VITE_USE_LOCAL_PROXY || null);
99+
setModelType('custom');
100+
setInitState('done');
101+
setIsFirstLaunch(false);
91102
dispatch({
92103
type: 'INITIALIZE',
93104
payload: { isAuthenticated: true },

0 commit comments

Comments
 (0)