@guestlinelabs/react-auth

中文文档
5.0.0发布于 2025/02/07ISCTypeScriptCommonJS零依赖近 30 天下载 7317

TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.

原始使用文档
文档目录6 节
  1. How to use it?
  2. Payload
  3. Contributing
  4. Running it locally
  5. Testing
  6. How to publish new version

ReactAuth

This library wraps the interface provided by the authentication script. It allows for a seamless integration with react. Authentication OC has been deprecated, and now you should use the new /authentication endpoint in the OC Registry.

How to use it?

  1. Install the library
npm i -S @guestlinelabs/react-auth
  1. Wrap you application/OC in the AuthProvider
import React from 'react';
import { AuthProvider } from '@guestlinelabs/react-auth';

import App from './App';

export default () => {
  return (
    <AuthProvider>
      <App />
    </AuthProvider>
  );
};
  1. Use the hook exposed by the library
import React from 'react';
import { useAuth } from '@guestlinelabs/react-auth';

export default () => {
  const authResult = useAuth();

  if (authResult.isLoading) {
    return <p>Loading...</p>;
  }

  if (!authResult.isAuthenticated) {
    return <p>You are not logged in...</p>;
  }

  return (
    <div>
      <p>accessToken: {authResult.accessToken}</p>
      <p>idToken: {authResult.idToken}</p>
      <p>userInfo: {JSON.stringify(authResult.userInfo)}</p>
    </div>
  );
};

Payload

The hook will return this payload:

type UseAuth = () => {
  isLoading: boolean;
  isAuthenticated: boolean;
  error: Error | null;
  accessToken: string | null;
  idToken: string | null;
  userInfo: UserInfo | null;

  // Those functions are mostly for the use of the Applications. Open components might use those functions in rare case, for example the logout function in the NavBar
  loginWithRedirect: LoginFunction;
  handleRedirectCallback: HandleLoginCallBackFunction;
  logout: LogoutFunction;
};

Please refer to the types in the library for more details.

Contributing

Please contact Sugoi team and send a PR.

Running it locally

  1. Run npm ci in the react-auth directory
  2. Run npm run build in the react-auth directory to build it
  3. Run npm link in the react-auth directory to make it globally available in your machine
  4. Run npm link @guestlinelabs/react-auth in your application's directory so it uses your local build
  5. Run npm run build once you have made changes to your application uses your new code

Testing

  1. Run npm ci in the react-auth directory
  2. Run npm test in the react-auth directory to start the tests

How to publish new version

From react-auth folder

  1. npm login use your username from npm.js, you need to be part of guestlinelabs organisation
  2. npm ci
  3. npm publish

版本与发布记录

@guestlinelabs/react-auth 共发布 40 个版本,首次发布于 2019/12/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.0latest2025/02/071.8 年前
4.3.22024/09/052 年前
4.3.12024/02/282 年前
4.3.02024/02/222 年前
4.2.02023/07/173 年前
4.1.02023/07/113 年前

关于 @guestlinelabs/react-auth 的常见问题

@guestlinelabs/react-auth 是什么?

TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.

如何安装 @guestlinelabs/react-auth?

在项目目录运行 npm install @guestlinelabs/react-auth,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^16.9.0 || ^17 || ^18 || ^19)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@guestlinelabs/react-auth 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@guestlinelabs/react-auth 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@guestlinelabs/react-auth 可以商用吗?

@guestlinelabs/react-auth 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@guestlinelabs/react-auth 的下载量有多少?

根据 npm 官方下载统计,@guestlinelabs/react-auth 在 2026/10/17 – 2026/11/15 这 30 天内被下载 7,317 次,日均约 244 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@guestlinelabs/react-auth 还在维护吗?

最新版本 5.0.0 发布于 2025/02/07(1.8 年前);至今共发布 40 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/12/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。