这是我到目前为止的代码,我尝试使用这个库@react-oauth/google,但也尝试使用google的官方文档。我无法取得好的结果。我希望按钮打开弹出方法而不是重定向方法(即使用当前代码,只是澄清一下)
使用此代码,我可以登录用户,但按钮语言始终是西班牙语(我来自阿根廷),当我选择意大利语作为默认应用程序语言时,它在我的应用程序中看起来非常奇怪。
有人可以帮忙吗?预先感谢
import React from 'react';
import { GoogleLogin, CredentialResponse } from '@react-oauth/google';
import { useTranslation } from 'react-i18next';
interface Props {
onSuccess: (credentialResponse: CredentialResponse) => void;
onFailure: (error: string) => void;
}
const GoogleLoginButton = ({ onSuccess, onFailure }: Props) => {
const { t, i18n } = useTranslation();
return (
<>
<GoogleLogin
onSuccess={(credentialResponse) => onSuccess(credentialResponse)}
onError={() => onFailure("")}
text='continue_with'
locale={i18n.language}
logo_alignment='center'
/>
</>
)
};
export default GoogleLoginButton;
我还从这个库中找到了一个 useGoogleLogin 钩子,但它返回了一个不同的 access_token,而不是后端所期望的 tokenId。
@react-oauth/google的文档中有一个用于自定义登录按钮的部分。试试这个:
<MyCustomButton onClick={() => login()}>t('your_i18n_variable', {ns:'your_namespace'})</MyCustomButton>;
希望它会起作用