我正在尝试在我的 React Native 应用程序中实现 Google 身份验证,并希望将所有数据存储在 Strapi 中。 Strapi 确实提供了 Google 身份验证支持,但我认为这可以与 SPA 一起使用。请帮助我如何在 React Native 中开始使用它。
我找到了一种使用 firebase 的直切方法
import { GoogleSignin } from "@react-native-google-signin/google-signin";
GoogleSignin.configure({
webClientId: "<web client ID>",
forceCodeForRefreshToken: true,
accountName: "",
});
const googleLogin = async () => {
await GoogleSignin.signOut();
await GoogleSignin.hasPlayServices();
await GoogleSignin.signIn();
const { accessToken } = await GoogleSignin.getTokens();
const response = await Api.get(
`${strapi_url}/api/auth/google/callback?access_token=${accessToken}`
);
};
// response -> you will have the strapi signed-in user
一切就绪!