react-nativeexpogoogle-oauthgoogle-api-js-clientappauth

How to use "promptAsync" from expo-auth-session, old library used in video tutorial was deprecated


I have been following the tinder 2.0 react native tutorial https://youtu.be/qJaFIGjyRms At 1:04:00 he sets the sign in method to: "await Google.logInAsync()" but I have noticed the google app auth library used in the video is now deprecated, I am redirected to use expo auth session instead but I notice there is a slight difference, where they used "await Google.logInAsync()" I must put "promptAsync" instead, when I do this I get the error promptAsync is undefined, I try with google.loginasync and get the same error that it is still undefined, what should I do? screenshot first screenshot

code:

    import React, { createContext, useContext } from 'react'
    //import * as Google from 'expo-auth-session/providers/google';
    import * as Google from 'expo-google-app-auth';

    const AuthContext = createContext({});

    const config = {
        androidClientId: 
        '236293699216-9a0nknjdq7ie79h40iubg0tddokgogfv.apps.googleusercontent.com',
        iosClientId: 
        '236293699216-6jdpm0rd6kn5d0qlbh1vgva5afgbqgib.apps.googleusercontent.com',
        scopes: ["profile", "email"],
        permissions: ["public_profile","email", "gender", "location"],
    }

    export const AuthProvider = ({ children}) => {
        const signInWithGoogle = async() => {
            await Google.logInAsync(config).then(async (logInResult) => {
                if (logInResult.type === "success") {
                    // login
                }
            });
        };

      return (
        <AuthContext.Provider
          value={{
          user: null,
            signInWithGoogle
        }}
        >
          {children}
        </AuthContext.Provider>
      )
    }

    export default function useAuth() {
        return useContext(AuthContext);
    }

I sought help on the forum that belongs to the maker of the video and other people had come across the same issue, one person recommended to go into package.json find the installed dependencies and change “expo-google-app-auth” from “^10.0.0” to “~9.0.0” and then npm I in the terminal, I have done this and I'm now getting the error “no such file or directory /Users/shangefagan/twinder-3/node_modules/expo-google-app-auth/node-modules/react-native/package.json” I have changed it back to “^10.0.0” but still getting the same error, screenshot screenshot of console do I just npm uninstall expo-google-app-auth and try to use expo-auth-session as I was originally trying? if so What is the correct way to use promptAsync from the expo-auth-session library

I check the docs for both libraries, expo google app auth: https://docs.expo.dev/versions/v43.0.0/sdk/google/ and expo auth session: https://docs.expo.dev/versions/latest/sdk/auth-session/ but I am unsure exactly how to use the new login method "promptAsync"


Solution

  • To use promptAsync you have to use the package expo-auth-session. Like you said expo-google-app-auth is deprecated.