npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@makeblock/passport-client

v1.5.9

Published

### 安装

Downloads

11

Readme

makeblock passport client

安装

yarn add @makeblock/passport-client

注意事项

  • @makeblock/passport-client 里面添集成了环境判断,默认是生成环境。若需要切换环境变量使用如下方式,使用 client.env 设置即可。client.env 是枚举类型,可从 @makeblock/passport-client 导出 CLIENT_ENV 即可,具体使用方式,参看下面文档。
  • 缓存用户 token 使用的是 cookie,所以需要注意 cookie 域可能存在问题,可以重新设置 client.cookieConfig

使用方式

// 引用
import client, { PAGE_MODE, CLIENT_ENV } from '@makeblock/passport-client';

// 设置环境,默认生成环境
client.env = CLIENT_ENV.TEST;
// 设置是否国际版本
client.intl = true;
// 设置 接入的平台标识
client.platform = '';
// 设置语言
client.lang = '';
// 设置 登录完成跳转回去的链接地址。
// 注:输入的网址不需要转义,我们会默认对其进行转义。
// 没有特殊情况不要设置该属性值。
client.redirect = '';
// 获取跳转登录页面的 URL
const url = client.url;

// 获取登录 URL
const registerUrl = client.getUrl('register');


// 根据获取的 URL 跳转即可。

获取用户登录 URL

const url = client.url;

获取学生账号登录 URL

const url = client.stuLoginUrl;

获取用户主页 URL

const url = client.profile;

获取用户 token

const utoken = client.token;

根据页面名称获取页面 URL

const url = client.getUrl('pathName');

网页内嵌方式登录(使用 iframe)

// 设置展示模式为窗口模式,默认页面形式
client.mode = PAGE_MODE.WIN;
// 设置登录成功回调,窗口模式才需要设置
client.close = (data: { type: string; token: string }) => {
    // to do something.
};
// 是否显示登陆注册切换
client.showSwitchLoginRegister = true;
// 是否显示第三方登陆
client.showSocialLogin = true;
// 是否仅手机号登录
client.onlyPhoneLogin = true;
// 是否使用 localstorage 存储策略
client.useLocalstorage = true;
// 重新登录,忽略已登录帐号
client.useReLogin = true;
// 使用自定义图片 logo
client.logo = 'https:'//xxxxx';
// 使用文字 logo
client.textLogo = 'xxxxx';
// 版权信息
client.copyright = 'xxxxx';
// 隐藏 Logo
client.hideLogo = true;
// 是否显示切换服务器的操作
client.showSwitchHost = true;
// 设置切换服务回调
client.switchHost = (isIntl: boolean) => {
    // to do something.
};
// 添加消息监听,返回出事件监听
const remove = client.listenMessage();

获取用信息

try {
    const user = await client.userInfo();
} catch (error) {
    // TODO: 未登录或登录失效
}

退出登录

try {
    await client.logout();
} catch (error) {
    // TODO: 退出登录失败
}

重置 cookeie 配置

client 会根据,是否是国际版自动切换 cookie 的域和过期时间。 中国版的 cookie 的域为 .makeblock.com。 国际版的 cookie 的域为 .mblock.cc。 默认有效期都是一年

修改配置方法

client.cookieConfig = {
    domain: 'xxxx', // 域
    expires: 60 // 过期时间
};