Skip to content

Commit b6a227f

Browse files
authored
Merge pull request chaitin#156 from guanweiwang/main
feat: 用户登录和管理员登录合一起
2 parents 341e1da + dd42cff commit b6a227f

6 files changed

Lines changed: 277 additions & 150 deletions

File tree

ui/api-templates/http-client.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ const redirectToLogin = () => {
4545
const redirectAfterLogin = encodeURIComponent(location.href);
4646
const search = `redirect=${redirectAfterLogin}`;
4747
const pathname = location.pathname.startsWith('/user')
48-
? '/user/login'
49-
: '/login';
50-
window.location.href = `${pathname}?${search}`;
48+
? '/login'
49+
: '/login/admin';
50+
window.location.href = `${pathname}`;
5151
};
5252

5353
type ExtractDataProp<T> = T extends { data?: infer U } ? U : never

ui/src/api/httpClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ const redirectToLogin = () => {
6565
const redirectAfterLogin = encodeURIComponent(location.href);
6666
const search = `redirect=${redirectAfterLogin}`;
6767
const pathname = location.pathname.startsWith("/user")
68-
? "/user/login"
69-
: "/login";
70-
window.location.href = `${pathname}?${search}`;
68+
? "/login"
69+
: "/login/admin";
70+
window.location.href = `${pathname}`;
7171
};
7272

7373
type ExtractDataProp<T> = T extends { data?: infer U } ? U : never;

ui/src/components/header/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const Header = () => {
1717
await postAdminLogout();
1818
}
1919
message.success('退出登录成功');
20-
navigate(pathname.startsWith('/user') ? '/user/login' : '/login');
20+
navigate(pathname.startsWith('/user') ? '/login/user' : '/login/admin');
2121
};
2222
return (
2323
<Stack

ui/src/main.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,26 @@ const App = () => {
107107

108108
const getUser = () => {
109109
setLoading(true);
110-
if (location.pathname.startsWith('/user')) {
110+
if (
111+
location.pathname.startsWith('/user') ||
112+
location.pathname === '/login' ||
113+
location.pathname === '/login/user'
114+
) {
111115
return getUserProfile()
112116
.then((res) => {
113117
setUser(res);
114-
if (location.pathname.startsWith('/user/login')) {
118+
if (location.pathname.startsWith('/login')) {
115119
onGotoRedirect('user');
116120
}
117121
})
118122
.finally(() => {
119123
setLoading(false);
120124
});
121-
} else if (!location.pathname.startsWith('/auth')) {
125+
} else if (
126+
!location.pathname.startsWith('/auth') ||
127+
!location.pathname.startsWith('/user') ||
128+
location.pathname === '/login/admin'
129+
) {
122130
return getAdminProfile()
123131
.then((res) => {
124132
setUser(res);

0 commit comments

Comments
 (0)