@cheyingwang/utils
v1.0.10
Published
```js const { setToken } = useAuth({ authUrl: "", loginByTicketApi: ({ ticket }) => { console.log(ticket); return xxxApi.then((token) => { // 登录后 setToken(token); }); }, }); ```
Downloads
13
Readme
后续完善
useAuth
中间页
const { setToken } = useAuth({
authUrl: "",
loginByTicketApi: ({ ticket }) => {
console.log(ticket);
return xxxApi.then((token) => {
// 登录后
setToken(token);
});
},
});
路由
const { routerCheck } = useAuthObserver({
loginPath: '/login'
})
...
router.beforeEach(async (to, from, next) => {
....
const nextParam = await routerCheck().then(flag => {
if(flag){
return {
path: '/'
};
}
// do something...
next();
}).catch(nextParam => {
return nextParam
})
if(nextParam){
next(nextParam);
}
....
})
登出后
const { logout } = useAuthObserver({
ssoLoginUrl: 'xxx/login',
logOutApi: ({token}) => {
return xxxApi
}
})
...
logout(() => {
// logout success...
})