我最喜欢的库,用于在我的 React 应用中提供 Google 的登录和注销功能
大家好,我是Aya Bouchiha,我决定与你们分享我最喜欢的 React 库,它在我的 React 应用程序中提供使用 Google 功能登录和注销的功能,即react-google-login。
react-google-login
安装
npm i react-google-login
yarn add react-google-login
登录代码
如果您没有客户端 ID,请查看此文章:如何获取 Google 客户端 ID 和客户端密钥。
import GoogleLogin from 'react-google-login';
const Login = () => {
    const handleSuccess = (response) => {
        console.log(response);
        alert("you're logged in successfully!");
    };
    const handleFailure = () => {
        alert('something went wrong');
    };
    return (
        <>
            <GoogleLogin
                // you client Id
                clientId={process.env.CLIENT_ID}
                buttonText='Login'
                onSuccess={handleSuccess}
                onFailure={handleFailure}
                // for calling onSuccess callback when the page load to keep the user logged in.
                isSignedIn={true}
            />
        </>
    );
};
注销代码
import { GoogleLogout } from 'react-google-login';
const Logout = () => {
    const handleLogout = () => {
        alert("you're logged out!!!");
    };
    return (
        <GoogleLogout
            clientId={process.env.CLIENT_ID}
            buttonText='Logout'
            onLogoutSuccess={handleLogout}>
        </GoogleLogout>
    );
};
祝你今天过得愉快
链接:https://dev.to/ayabouchiha/my-favourite-library-for-providing-logging-in-logging-out-with-google- functionalities-in-my-react-apps-50l0 后端开发教程 - Java、Spring Boot 实战 - msg200.com
            后端开发教程 - Java、Spring Boot 实战 - msg200.com