mirror of https://github.com/halo-dev/halo
feat: support for configuring the redirection location after login for roles (#4918)
#### What type of PR is this? /area console /kind feature /milestone 2.11.x #### What this PR does / why we need it: 支持为自定义的角色配置登录之后默认跳转位置。 #### Special notes for your reviewer: 1. 创建一个新的角色,设置跳转位置。 2. 为一个用户赋予这个角色。 3. 测试登录之后是否正常跳转到设置的位置。 #### Does this PR introduce a user-facing change? ```release-note 支持为自定义的角色配置登录之后默认跳转位置。 ```pull/4878/head^2
parent
927398b6bd
commit
82a6ba6d90
|
@ -154,6 +154,15 @@ const handleResetForm = () => {
|
||||||
type="text"
|
type="text"
|
||||||
validation="required|length:0,50"
|
validation="required|length:0,50"
|
||||||
></FormKit>
|
></FormKit>
|
||||||
|
<FormKit
|
||||||
|
v-model="
|
||||||
|
formState.metadata.annotations[
|
||||||
|
rbacAnnotations.REDIRECT_ON_LOGIN
|
||||||
|
]
|
||||||
|
"
|
||||||
|
type="text"
|
||||||
|
label="登录之后默认跳转位置"
|
||||||
|
></FormKit>
|
||||||
</FormKit>
|
</FormKit>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { rbacAnnotations } from "@/constants/annotations";
|
||||||
import { useUserStore } from "@/stores/user";
|
import { useUserStore } from "@/stores/user";
|
||||||
import type { Router } from "vue-router";
|
import type { Router } from "vue-router";
|
||||||
|
|
||||||
|
@ -29,14 +30,28 @@ export function setupAuthCheckGuard(router: Router) {
|
||||||
redirect_uri: to.query.redirect_uri,
|
redirect_uri: to.query.redirect_uri,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const roleHasRedirectOnLogin = userStore.currentRoles?.find(
|
||||||
|
(role) =>
|
||||||
|
role.metadata.annotations?.[rbacAnnotations.REDIRECT_ON_LOGIN]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (roleHasRedirectOnLogin) {
|
||||||
|
window.location.href =
|
||||||
|
roleHasRedirectOnLogin.metadata.annotations?.[
|
||||||
|
rbacAnnotations.REDIRECT_ON_LOGIN
|
||||||
|
] || "/";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
next({
|
next({
|
||||||
name: "Dashboard",
|
name: "Dashboard",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,6 +11,7 @@ export enum rbacAnnotations {
|
||||||
DEPENDENCIES = "rbac.authorization.halo.run/dependencies",
|
DEPENDENCIES = "rbac.authorization.halo.run/dependencies",
|
||||||
AVATAR_ATTACHMENT_NAME = "halo.run/avatar-attachment-name",
|
AVATAR_ATTACHMENT_NAME = "halo.run/avatar-attachment-name",
|
||||||
LAST_AVATAR_ATTACHMENT_NAME = "halo.run/last-avatar-attachment-name",
|
LAST_AVATAR_ATTACHMENT_NAME = "halo.run/last-avatar-attachment-name",
|
||||||
|
REDIRECT_ON_LOGIN = "rbac.authorization.halo.run/redirect-on-login",
|
||||||
}
|
}
|
||||||
|
|
||||||
// content
|
// content
|
||||||
|
|
Loading…
Reference in New Issue