使用适用于 React 的新 Google 身份服务 SDK 的 Google OAuth2
React OAuth 是一组适用于 React 应用程序的生产就绪的 OAuth2 库。每个包都设计得简单、类型安全且易于集成到您的项目中。
| 包 | 描述 | NPM |
|---|---|---|
| @React-oauth/google | 使用新的 Google 认证服务 SDK 的 Google OAuth2 | |
| @React-oauth/GitHub | GitHub OAuth 身份验证的现代 React 钩子 |
npm install @react-oauth/google
# or
yarn add @react-oauth/google基本用法:
import { GoogleOAuthProvider, GoogleLogin } from '@react-oauth/google';
function App() {
return (
">
{
console.log(credentialResponse);
}}
onError={() => {
console.log('Login Failed');
}}
/>
);
}功能:
npm install @react-oauth/github
# or
yarn add @react-oauth/github基本用法:
import { useGitHubLogin } from '@React-oauth/GitHub';
function LoginButton() {
const { initiateGitHubLogin, isLoading } = useGitHubLogin({
clientId: '你的 GitHub 客户端 ID',
redirectUri: 'http://localhost:3000/callback',
onSuccess: response => {
console.log('授权码:', resp暂无开放 Issues,或尚未同步最近议题。