yg-auth-docking

1.0.8 • Public • Published

yg-auth-docking

实现与yg-auth的对接

  • 下载与安装
npm install yg-auth-docking
  • 配置并创建实例
import YGAD from 'yg-auth-docking'
 
const ygad = new YGAD({
  BASEURL: '',
  ASSET_BASEURL: '',
  DEFAULT_HEAD: '',
  LOGIN_URL: '',
  TOKEN_NAME: '',
  QUERY_PARAM: '',
  USER_TAG: ''
})
 
  • 登录检测
ygad.checkLogin().then(rs => {
  if (rs && rs.stuid) {
    // 已登录
    // next()
    // TODO
  } else {
    // 未登录
    // 去登录
    ygad.gotoLogin()
  }
}).catch(() => {
  // 登录过期或出现错误 2s后重新登录
  // Notification.error({
  //   message: '错误提示',
  //   description: '未登录,或登录过期',
  // })
  setTimeout(() => {
    ygad.gotoLogin()
  }, 2000)
})
  • 获取已登录用户信息
ygad.getStorage(ygad.config.USER_TAG)
// 用户信息
ygad.getStorage(ygad.config.TOKEN_NAME)
// token
  • 删除已登录用户信息
ygad.rmStorage(ygad.config.USER_TAG)
// 用户信息
ygad.rmStorage(ygad.config.TOKEN_NAME)
// token
  • 通过token获取用户信息
const token = ygad.getQueryString('token') || ygad.getStorage(ygad.config.TOKEN_NAME) || ''
ygad.getUserInfor(token).then(e => {
  // TODO
})
  • 注销登录
ygad.logout()

Readme

Keywords

Package Sidebar

Install

npm i yg-auth-docking

Weekly Downloads

0

Version

1.0.8

License

MIT

Unpacked Size

15.1 kB

Total Files

6

Last publish

Collaborators

  • w-xuefeng