Skip to content

Commit f7416eb

Browse files
authored
feat: auto-login after admin account setup (langgenius#24395)
1 parent fe06d26 commit f7416eb

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

web/app/install/installForm.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Loading from '../components/base/loading'
1414
import classNames from '@/utils/classnames'
1515
import Button from '@/app/components/base/button'
1616

17-
import { fetchInitValidateStatus, fetchSetupStatus, setup } from '@/service/common'
17+
import { fetchInitValidateStatus, fetchSetupStatus, login, setup } from '@/service/common'
1818
import type { InitValidateStatusResponse, SetupStatusResponse } from '@/models/common'
1919
import useDocumentTitle from '@/hooks/use-document-title'
2020
import { useDocLink } from '@/context/i18n'
@@ -54,12 +54,32 @@ const InstallForm = () => {
5454
})
5555

5656
const onSubmit: SubmitHandler<AccountFormValues> = async (data) => {
57+
// First, setup the admin account
5758
await setup({
5859
body: {
5960
...data,
6061
},
6162
})
62-
router.push('/signin')
63+
64+
// Then, automatically login with the same credentials
65+
const loginRes = await login({
66+
url: '/login',
67+
body: {
68+
email: data.email,
69+
password: data.password,
70+
},
71+
})
72+
73+
// Store tokens and redirect to apps if login successful
74+
if (loginRes.result === 'success') {
75+
localStorage.setItem('console_token', loginRes.data.access_token)
76+
localStorage.setItem('refresh_token', loginRes.data.refresh_token)
77+
router.replace('/apps')
78+
}
79+
else {
80+
// Fallback to signin page if auto-login fails
81+
router.replace('/signin')
82+
}
6383
}
6484

6585
const handleSetting = async () => {

0 commit comments

Comments
 (0)