1.登录页判断是否有token
1.先从route中获取token,没有的话跳转公司登录页进行扫码登录或者账号密码登录;登录成功后url中会有token相关信息
2.获取url中token并调公司验证token接口进行验证token的可用性,并将token存储在浏览器中
const ssoLogin = async () => {
const route = useRoute();
const token = route.query?.token;
console.log(token);
if (token) {
try {
const res = await verifyToken({ project: VITE_SSO_PROJECT_ID, token });
const { P } = res;
const param: any = {
accessToken: token,
refreshToken: "adminRefresh",
expires: "2030/10/30 00:00:00",
username: P.name,
nickname: P.engName + "," + P.region,
// 一个用户可能有多个角色
roles: [],
avatar: P.avatar
};
setToken(param);
} else {
window.location.href = `https://sso.xiaoxitech.com/login?project=${VITE_SSO_PROJECT_ID}&cb=${encodeURIComponent(VITE_PROJECT_PATH)}`;
}
2.在请求接口中携带token进行请求
3.登出操作
在注销时通知SSO系统,并清除本地存储信息,跳转到登录页
logOut() {
const data = getToken();
logout({
project: VITE_SSO_PROJECT_ID,
token: data.accessToken
}).then(() => {
this.username = "";
this.roles = [];
removeToken();
useMultiTagsStoreHook().handleTags("equal", [...routerArrays]);
resetRouter();
window.location.href = `https://sso.xiaoxitech.com/login?project=${VITE_SSO_PROJECT_ID}&cb=${encodeURIComponent(VITE_PROJECT_PATH)}`;
});
// router.push("/login");
},