skip to Main Content

I have my web apps which use google authentication configured via passportjs in my express backend. Now i want to create react-native apps for the same. I am trying to implement google signin using same apis, but it is not working.

On my backend:

  1. I have /auth/google endpoint which triggers the google signin page
  2. on success it redirects back to a callback url /auth/google/callback
  3. then it redirects back to the frontend(client) url.

Now in case of react-native apps, i open the /auth/google in a webview, which triggers the google signin page, on success it gets to callback url and then while redirecting back to frontend(client), i do res.redirect(myapp://app/login), but it shows Cannot GET /auth/google/myapp:app//login.

2

Answers


  1. Chosen as BEST ANSWER

    I was able to redirect back to app using res.redirect("intent://app/login#Intent;scheme=myapp;package=com.myapp;end")


  2. You can use following SDK for google authentication in react native which does’t required backend API or webView:

      yarn add  @react-native-google-signin/google-signin
    

    call config method in early stage like App.js

     import { GoogleSignin } from '@react-native-google-signin/google- 
      signin';
    
      GoogleSignin.configure(); // you can also setup custom config
    

    then you can use you SDK any where like this:

      // import statusCodes along with GoogleSignin
      import { GoogleSignin, statusCodes } from '@react-native-google- 
     signin/google-signin';
    
     // Somewhere in your code
     signIn = async () => {
      try {
     await GoogleSignin.hasPlayServices();
     const userInfo = await GoogleSignin.signIn();
     setState({ userInfo });
      } catch (error) {
     if (error.code === statusCodes.SIGN_IN_CANCELLED) {
      // user cancelled the login flow
      } else if (error.code === statusCodes.IN_PROGRESS) {
       // operation (e.g. sign in) is in progress already
      } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
      // play services not available or outdated
      } else {
       // some other error happened
       }
      }
      };
    

    you can also visit SDK documentation :@react-native-google-signin/google-signin

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search