jusda-tools-auth-tools
v0.0.24
Published
>`npm i @jusda/auth-tools --registry=http://nexus.jusda.int/repository/npm-group`
Downloads
1
Readme
jusda 权限认证工具函数
npm i @jusda/auth-tools --registry=http://nexus.jusda.int/repository/npm-group
or
yarn add @jusda/auth-tools --registry=http://nexus.jusda.int/repository/npm-group
import authTools from '@jusda/auth-tools'
const {
AuthLogin,
AuthApplication,
CookieTools,
JusdaUserInfo,
} = authTools;
全局参数配置
AuthLogin 统一认证鉴权
window.jusdaBaseConfig = {
//clientId
clientId: 'clientId',
// 部署环境
cfgType: 'dev',
};
AuthApplication 跨应用鉴权
window.jusdaBaseConfig = {
//clientId
clientId: 'clientId',
// 部署环境
cfgType: 'dev',
};
CookieTools
const cookieTools = new CookieTools();
// 获取cookie
cookieTools.get('Jusda_token');
// 设置cookie return Promise
cookieTools.set({'Jusda_token','0123'});
const value = await cookieTools.set({'Jusda_token','0123'});
// 删除cookie
cookieTools.remove('Jusda_token');
JusdaUserInfo
const jusdaUserInfo = new JusdaUserInfo();
// 获取用户所有信息
jusdaUserInfo.getFullInfo();
Usage
dva with create-react-app
// dir
// src/index.js
import authTools from '@jusda/auth-tools';
const { AuthLogin, AuthApplication } = authTools;
// 1. Initialize
// ...
// 2. Plugins
// ...
// 3. Model
// ...
// 4. Router
// ...
async function bootstrap() {
// 统一认证鉴权
await AuthLogin();
// 跨应用鉴权
await AuthApplication(});
app.start('#root');
}
// 5. Start
bootstrap();
umijs
// dir
// /src/app.js
import authTools from '@jusda/auth-tools';
export const dva = {
config: {
onError(err) {
err.preventDefault();
console.error(err.message);
},
},
};
const { AuthLogin, AuthApplication } = authTools;
export async function render(oldRender) {
// 统一认证鉴权
await AuthLogin(});
// 跨应用鉴权
await AuthApplication();
oldRender();
}