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 🙏

© 2026 – Pkg Stats / Ryan Hefner

zungen-auth-util

v1.1.2

Published

``` 通过git克隆或下载项目,将auth-util相关文件复制到项目 ```

Readme

安装

通过git克隆或下载项目,将auth-util相关文件复制到项目

使用示例

import AuthUtil from 'auth-util/index';

class Example extends Component {
    constructor(props) {
        super(props)
        this.origin = project.http.authHost;
        this.state = {
            hasToken: false // 没有token访问非登录页就不渲染,防止无意义的接口调用
        }
    }

    componentDidMount () {
        this.authUtil = new AuthUtil({
            root: 'auth-util-wrapper',
            authHost: this.origin,
            onGetUserInfo: this.onGetUserInfo,
            onLocalStorageChange: this.onLocalStorageChange
        });
        this.authUtil.init();
    }

    redirect = (pathname = this.props.location.pathname) => {
        if (localStorage.token) {
            this.setState({
                hasToken: true
            });
        } else {
            this.setState({
                hasToken: false
            });
            /* 如果没有token跳转到登录页 */
            this.authUtil.toLogin()
        }
    };

    /* 获取userInfo后开始显示页面并根据token获取权限 */
    onGetUserInfo = () => {
        this.setState({
            hasToken: true
        });
        authService.getAuthAction().then(res => {
            if (!publicUtils.isOk(res)) return;
            localStorage.setItem('authAction', res.data.result);
            this.getMenuForPathname();
        });
    };

    /*
    更新重新登陆弹窗剩余时间
    tokenExpire token结束时间
    * */
    updateTokenExpTimeMs = (tokenExpire) => {
        if (tokenExpire === localStorage.tokenExpire) return;
        /* 计算重新token有效剩余时间 */
        const tokenExpTimeMs = tokenExpire - new Date().getTime();
        GlobalStore.setTokenExpTimeMsValue(tokenExpTimeMs);
        GlobalStore.setIsTokenExpTimeMs(false);
    };

    onLocalStorageChange = (key, value) => {
        switch (key) {
            case 'tokenExpire':
                this.updateTokenExpTimeMs(value);
                break;
            case 'token':
                GlobalStore.setIsTokenExpTimeMs(false);
                break;
        }
    };

    logoutTest = () => {
        this.authUtil.logout();
    };

    render() {
        return (
            <Provider GlobalStore={ GlobalStore }>
                <div style={ { height: '100%' } }>
                    <div id="auth-util-wrapper" hidden></div>
                    <div style={ { height: '100%' } }>
                        <div><button onClick={ this.logoutTest }>登出</button></div>
                        <ConfigProvider locale={ zh_CN }>
                            <Switch>
                                <Route path="/login" component={ Login }/>
                                <Route path='/' component={ this.state.hasToken ? Layouts : '' }/>
                            </Switch>
                        </ConfigProvider>
                    </div>
                </div>
            </Provider>
        )
    }
}

export default Routers

实例化参数

 root: 必须 --- 根节点id,决定插入位置
 authHost: 必须 --- 鉴权系统地址,即现在的综合管理系统
 id: iframe的id
 iframeProps: 自定义iframe的props
 onGetUserInfo: 获取userInfo后的回调
 onGetUserInfoFail: 获取userInfo失败后的回调
 onLocalStorageChange: 修改localStorage后回调,携带修改的localStorage的key和value,如callback(key, value)
 fileNames: localStorage的key重命名,如 { token: 'workbench_token' } 意为将默认key token改为workbench_token

实例方法

authUtil.init()

初始化

authUtil.postMessage(type, data = {})

向iframe发送消息

authUtil.toLogin(withToken = false)

跳转到鉴权系统登录页,并携带当前地址到url以便返回。可传入true以带回token到url上

authUtil.logout()

登出系统,清除本地包括token等的用户信息,并跳转到综管登录页

authUtil.updateLocalStorage(partialLocalStorage)

发送消息给iframe,通知鉴权系统更新localStorage