Code Monkey home page Code Monkey logo

Comments (2)

MomenSherif avatar MomenSherif commented on June 12, 2024

Hey,
GoogleOAuthProvider is just a react context, and doesn't need to be wrapped in the top level <App />, you must wrap the usage of GoogleButton or useGoogleLogin

so you can provider multiple GoogleOAuthProvider and your component will talk to the first parent that provider context value

from react-oauth.

Akitektuo avatar Akitektuo commented on June 12, 2024

Hi,
Thank you for your response, that's what I was expecting from the code, but instead of redirecting the user to the Google Page login just does nothing, removing any elements placed by us indicating that the application is loading. I can work on a sample to reproduce the issue if it helps so I can showcase the bug. Or do you know if someone else had this issue in the past and was just a misconfiguration on their part?

Below you can find how login is declared inside useGoogleAuthenticationService.

import { useLocation } from "react-router-dom";
import { GoogleAuthenticationService } from "../services/authentication/googleAuthenticationService";
import useGlobalState from "./useGlobalState";
import store from "../store";
import { useEffect, useMemo } from "react";
import { useGoogleLogin } from "@react-oauth/google";

const useGoogleAuthenticationService = (googleAuthenticationService: GoogleAuthenticationService) => {
    const { isAppLoading, hasError } = useGlobalState(store.auth);
    const { search } = useLocation();
    const code = useMemo(() => new URLSearchParams(search).get("code"), [search]);

    const login = useGoogleLogin({
        flow: "auth-code",
        scope: "openid email",
        ux_mode: "redirect",
        onError: console.error,
        onNonOAuthError: console.error
    });

    useEffect(() => {
        if (isAppLoading || hasError) return;

        if (code) {
            googleAuthenticationService.signIn(code);
        } else {
            login();
        }
    }, [isAppLoading, hasError, code, login]);
};

export default useGoogleAuthenticationService;

from react-oauth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.