forwardsoftware/react-auth
关于
Simplify your Auth flow when working with React apps
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文React Auth
Simplify your Auth flow when working with React apps
Packages
This monorepo contains the following packages:
| Package | Version | Description |
|---|---|---|
@forward-software/react-auth |
Core library — provides AuthClient, AuthProvider, createAuth, and useAuthClient for integrating authentication flows in any React or React Native app |
|
@forward-software/react-auth-google |
Google Sign-In adapter -- ready-made AuthClient implementation and drop-in GoogleSignInButton for Web and React Native (Expo) |
|
@forward-software/react-auth-apple |
Apple Sign-In adapter -- ready-made AuthClient implementation and drop-in AppleSignInButton for Web and React Native (Expo) |
Examples
The examples folder contains some examples of how you can integrate these libraries in your React app:
| Example | Description |
|---|---|
base |
Basic authentication flow using @forward-software/react-auth |
reqres |
Authentication using the ReqRes API |
refresh-token |
Token refresh flow with Axios interceptors |
expo |
React Native (Expo) integration |
Quick Start
Install the core library:
npm install @forward-software/react-auth
Define your auth client:
import { createAuth, type AuthClient } from '@forward-software/react-auth';
const authClient: AuthClient = {
onLogin: async (credentials) => {
// Exchange credentials for tokens
return { token: '...' };
},
};
export const { AuthProvider, useAuthClient } = createAuth(authClient);
Wrap your app:
import { AuthProvider } from './auth';
function App() {
return (
<AuthProvider>
<YourApp />
</AuthProvider>
);
}
Use the hook to interact with the auth client:
import { useAuthClient } from './auth';
function LoginButton() {
const authClient = useAuthClient();
return <button onClick={() => authClient.login({ username: '...', password: '...' })}>Log in</button>;
}
For more details, see the @forward-software/react-auth README.
Looking for a ready-made integration? The
@forward-software/react-auth-googlepackage provides a drop-in Google Sign-In adapter and the@forward-software/react-auth-applepackage provides Apple Sign-In -- both with a pre-builtAuthClientand sign-in button for Web and React Native. See their READMEs for setup instructions.
Project Structure
This project is a monorepo managed with pnpm workspaces:
react-auth/
├── lib/ # @forward-software/react-auth (core library)
├── packages/
│ ├── google-signin/ # @forward-software/react-auth-google (Google Sign-In adapter)
│ │ ├── src/
│ │ │ ├── web/ # Web implementation (Google Identity Services)
│ │ │ └── native/ # React Native implementation (Expo module)
│ │ ├── android/ # Android native module
│ │ ├── ios/ # iOS native module
│ │ └── test/ # Unit tests
│ └── apple-signin/ # @forward-software/react-auth-apple (Apple Sign-In adapter)
│ ├── src/
│ │ ├── web/ # Web implementation (Sign in with Apple JS)
│ │ └── native/ # React Native implementation (Expo module)
│ ├── android/ # Android native module
│ ├── ios/ # iOS native module
│ └── test/ # Unit tests
└── examples/ # Example applications
├── base/ # Basic React example
├── reqres/ # ReqRes API example
├── refresh-token/ # Token refresh example
└── expo/ # React Native (Expo) example
For a detailed breakdown of the source layout and architecture, see the Contributing Guide.
Getting Started
Prerequisites
Installation
pnpm install
See the Contributing Guide for the full list of build, test, and lint commands.
Contributing
Contributions are welcome! Here's how to get started:
- Fork the repo and create your branch from
main - Install dependencies:
pnpm install - Make your changes and add/update tests
- Ensure everything works:
pnpm -r lint && pnpm -r test && pnpm -r build - Commit using Conventional Commits (e.g.,
feat: ...,fix: ...) - Open a pull request
For more details, read the Contributing Guide and the Code of Conduct.
Found a security issue? Please report it privately — see our Security Policy.
Credits
This library has been inspired by react-keycloak and similar libraries.
License
MIT
Made with ✨ & ❤️ by ForWarD Software and contributors
If you found this project to be helpful, please consider contacting us to develop your React and React Native projects.
探索相关项目
加载中…