aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.4k stars 2.11k forks source link

Federated sign-in: [TypeError: Cannot read property 'oauthSignIn' of undefined] #11313

Closed jvgeee closed 6 months ago

jvgeee commented 1 year ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

``` # Put output below this line System: OS: macOS 13.3.1 CPU: (8) arm64 Apple M1 Memory: 96.27 MB / 8.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.19.1 - ~/.nvm/versions/node/v16.19.1/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 8.19.3 - ~/.nvm/versions/node/v16.19.1/bin/npm Watchman: 2023.04.24.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 112.0.5615.137 Safari: 16.4 npmPackages: @babel/core: ^7.20.0 => 7.21.3 (7.21.4) @babel/plugin-proposal-decorators: 7.20. => 7.21.0 @babel/plugin-proposal-optional-catch-binding: 7.16.7 => 7.16.7 (7.18.6) @babel/preset-env: ^7.20.0 => 7.20.2 @babel/runtime: ^7.20.0 => 7.21.0 @expo-google-fonts/space-grotesk: ^0.2.2 => 0.2.3 @expo/webpack-config: ^18.0.1 => 18.0.2 @react-native-async-storage/async-storage: ^1.18.1 => 1.18.1 @react-native-community/cli-platform-ios: ^8.0.2 => 8.0.6 (10.2.1) @react-native-community/eslint-config: ^3.2.0 => 3.2.0 @react-native-community/netinfo: ^9.3.9 => 9.3.9 @react-native-firebase/analytics: ^17.3.1 => 17.4.0 @react-native-firebase/app: ^17.3.1 => 17.4.0 @react-navigation/bottom-tabs: ^6.3.2 => 6.5.7 @react-navigation/native: ~6.0.1 => 6.0.16 @react-navigation/native-stack: ^6.0.2 => 6.9.12 @react-navigation/stack: ~6.2.1 => 6.2.3 @sentry/react-native: ^5.2.0 => 5.2.0 @tsconfig/react-native: ^2.0.2 => 2.0.3 @types/i18n-js: 3.8.2 => 3.8.2 @types/jest: ^29.2.1 => 29.5.0 @types/react: ^18.0.24 => 18.0.31 (17.0.55) @types/react-native: 0.67.8 => 0.67.8 @types/react-test-renderer: ^18.0.0 => 18.0.0 @typescript-eslint/eslint-plugin: 5.28.0 => 5.28.0 (5.57.0) @typescript-eslint/parser: 5.28.0 => 5.28.0 (5.57.0) ContextAPIMixpanel: 0.0.1 HelloWorld: 0.0.1 MixpanelDemo: 0.0.1 SimpleMixpanel: 0.0.1 TypingIndicatorExample: 0.0.1 amazon-cognito-identity-js: ^6.2.0 => 6.2.0 apisauce: 2.1.5 => 2.1.5 appcenter: 4.4.5 => 4.4.5 appcenter-analytics: 4.4.5 => 4.4.5 appcenter-crashes: 4.4.5 => 4.4.5 aws-amplify: ^5.1.3 => 5.1.3 aws-amplify-react-native: ^7.0.2 => 7.0.2 aws-api-gateway-client: ^0.3.7 => 0.3.7 aws-sdk: ^2.1328.0 => 2.1345.0 axios: ^1.3.4 => 1.3.4 (0.26.0, 0.21.4, 0.19.0-beta.1) babel-jest: ^29.2.1 => 29.5.0 (26.6.3) babel-loader: 8.2.5 => 8.2.5 (8.3.0) core-js: ^3.30.1 => 3.30.1 (2.6.12) date-fns: ^2.29.2 => 2.29.3 detox: 19.12.1 => 19.12.1 detox-expo-helpers: 0.6.0 => 0.6.0 eslint: ^8.19.0 => 8.37.0 eslint-config-prettier: 8.5.0 => 8.5.0 (8.8.0) eslint-config-standard: 17.0.0 => 17.0.0 eslint-plugin-import: 2.26.0 => 2.26.0 eslint-plugin-n: ^15.0.0 => 15.6.1 eslint-plugin-node: 11.1.0 => 11.1.0 eslint-plugin-promise: 6.0.0 => 6.0.0 eslint-plugin-react: 7.30.0 => 7.30.0 (7.32.2) eslint-plugin-react-native: 4.0.0 => 4.0.0 expo: ^48.0.0 => 48.0.9 expo-application: ~5.1.1 => 5.1.1 expo-av: ^13.2.1 => 13.2.1 expo-constants: ~14.2.1 => 14.2.1 expo-detox-hook: 1.0.10 => 1.0.10 expo-device: ~5.2.1 => 5.2.1 expo-file-system: ~15.2.2 => 15.2.2 expo-font: ~11.1.1 => 11.1.1 expo-linear-gradient: ~12.1.2 => 12.1.2 expo-linking: ~4.0.1 => 4.0.1 expo-localization: ~14.1.1 => 14.1.1 expo-modules-autolinking: ~1.1.0 => 1.1.2 expo-modules-core: ~1.2.6 => 1.2.6 expo-notifications: ^0.18.1 => 0.18.1 expo-permissions: ^14.1.1 => 14.1.1 expo-splash-screen: ~0.18.1 => 0.18.1 expo-status-bar: ~1.4.2 => 1.4.4 expo-web-browser: ~12.1.1 => 12.1.1 fbjs-scripts: 3.0.1 => 3.0.1 firebase: ^9.17.1 => 9.18.0 firebase/analytics: undefined () firebase/app: undefined () firebase/app-check: undefined () firebase/auth: undefined () firebase/auth/cordova: undefined () firebase/auth/react-native: undefined () firebase/compat: undefined () firebase/compat/analytics: undefined () firebase/compat/app: undefined () firebase/compat/app-check: undefined () firebase/compat/auth: undefined () firebase/compat/database: undefined () firebase/compat/firestore: undefined () firebase/compat/functions: undefined () firebase/compat/installations: undefined () firebase/compat/messaging: undefined () firebase/compat/performance: undefined () firebase/compat/remote-config: undefined () firebase/compat/storage: undefined () firebase/database: undefined () firebase/firestore: undefined () firebase/firestore/lite: undefined () firebase/functions: undefined () firebase/installations: undefined () firebase/messaging: undefined () firebase/messaging/sw: undefined () firebase/performance: undefined () firebase/remote-config: undefined () firebase/storage: undefined () i18n-js: 3.9.2 => 3.9.2 jest: ^29.2.1 => 29.5.0 jest-circus: 26 => 26.6.3 (29.5.0) jest-environment-node: 26 => 26.6.2 (29.5.0) jest-expo: ^47.0.0 => 47.0.1 lodash: ^4.17.21 => 4.17.21 metro-react-native-babel-preset: 0.73.9 => 0.73.9 (0.73.8) mixpanel-react-native: ^2.2.1 => 2.2.1 mobx: 6.6.0 => 6.6.0 mobx-react-lite: 3.4.0 => 3.4.0 mobx-state-tree: 5.1.5 => 5.1.5 mocha: 6 => 6.2.3 patch-package: 6.4.7 => 6.4.7 postinstall-prepare: 1.0.1 => 1.0.1 prettier: ^2.4.1 => 2.8.7 query-string: ^8.1.0 => 8.1.0 (7.1.3, 5.1.1, 6.10.1) react: 18.2.0 => 18.2.0 (16.14.0) react-devtools-core: 4.24.7 => 4.24.7 (4.27.4) react-dom: 18.2.0 => 18.2.0 react-hook-form: ^7.43.2 => 7.43.8 react-native: 0.71.7 => 0.71.7 react-native-bootsplash: ^4.6.0 => 4.6.0 react-native-canvas: ^0.1.38 => 0.1.38 react-native-code-push: ^8.0.0 => 8.0.0 react-native-config: 1.4.12 => 1.4.12 react-native-gesture-handler: ~2.9.0 => 2.9.0 react-native-get-random-values: ^1.8.0 => 1.8.0 react-native-gifted-chat: ^2.0.1 => 2.0.1 react-native-keyboard-aware-scroll-view: ^0.9.5 => 0.9.5 react-native-keychain: ^8.1.1 => 8.1.1 react-native-reanimated: ~2.14.4 => 2.14.4 react-native-reanimated-carousel: ^3.3.0 => 3.3.0 react-native-redash: 14.0.4 => 14.0.4 react-native-render-html: ^6.3.4 => 6.3.4 react-native-safe-area-context: 4.5.0 => 4.5.0 react-native-screens: ~3.20.0 => 3.20.0 react-native-svg: ^13.9.0 => 13.9.0 react-native-svg-transformer: ^1.0.0 => 1.0.0 react-native-typing-animation: ^0.1.7 => 0.1.7 react-native-web: ^0.18.7 => 0.18.12 react-native-webview: 11.26.0 => 11.26.0 reactotron-core-client: ^2.8.10 => 2.8.10 (2.8.9) reactotron-mst: 3.1.4 => 3.1.4 reactotron-react-js: ^3.3.7 => 3.3.8 reactotron-react-native: 5.0.3 => 5.0.3 regenerator-runtime: ^0.13.4 => 0.13.11 (0.11.1) ts-jest: 26 => 26.5.6 typescript: ^4.9.4 => 4.9.5 webpack: 4 => 4.46.0 (5.76.3) webpack-dev-server: ^3 => 3.11.3 (4.13.1) npmGlobalPackages: @aws-amplify/cli: 10.8.1 appcenter-cli: 2.13.6 aws-sdk: 2.1334.0 corepack: 0.15.1 expo-cli: 6.3.2 npm: 8.19.3 serverless: 3.28.1 ```

Describe the bug

I'm doing a release build on Android for React Native, and I'm trying to do federated sign in with Google, like so:

Auth.federatedSignIn({
          provider: CognitoHostedUIIdentityProvider.Google
})

When I do this, I get [TypeError: Cannot read property 'oauthSignIn' of undefined]

Expected behavior

It should launch the oAuth screen for Google, instead nothing happens.

Reproduction steps

const MyApp = () => {

const signIn = async () => {
    await Auth.federatedSignIn({
          provider: CognitoHostedUIIdentityProvider.Google
      })
}

return <Button text="Sign in with Google" onPress={signIn} />
}

Code Snippet

No response

Log output

No response

aws-exports.js

/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "ap-southeast-2",
    "aws_cognito_identity_pool_id": "ap-southeast-2:xxxxxx",
    "aws_cognito_region": "ap-southeast-2",
    "aws_user_pools_id": "ap-southeast-2_xxxxxx",
    "aws_user_pools_web_client_id": "xxxxxx",
    "oauth": {
        "domain": "xxxxxx.auth.ap-southeast-2.amazoncognito.com",
        "scope": [
            "phone",
            "email",
            "openid",
            "profile",
            "aws.cognito.signin.user.admin"
        ],
        "redirectSignIn": "com.myapp.name://",
        "redirectSignOut": "com.myapp.name://",
        "responseType": "code"
    },
    "federationTarget": "COGNITO_USER_POOLS",
    "aws_cognito_username_attributes": [
        "EMAIL"
    ],
    "aws_cognito_social_providers": [
        "FACEBOOK",
        "GOOGLE",
        "APPLE"
    ],
    "aws_cognito_signup_attributes": [
        "EMAIL"
    ],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [
        "SMS"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ]
};

export default awsmobile;

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

nadetastic commented 1 year ago

Hi @jvgeee, thank you for opening this issue.

The error you see usually happens if you try to use Social sign in without it being properly configured - however, looking at your aws-exports.js it appears that you have it configured correctly.

A few questions:

Additionally, please also share the versions of React Native and aws-amplify that you are using in this project.

jvgeee commented 1 year ago

@nadetastic from testing this seems to affect release builds and not debug builds. E.g. I just did a production (release) build in Xcode and oAuth failed, but when I change the build profile to debug mode it works.

Any idea why that might be?

Also to answer your questions:

from yarn list:

jvgeee commented 1 year ago

@nadetastic Any thoughts on this?

edgardcooper-lukasdemeyere commented 1 year ago

We're also experiencing the same issue, any updates?

edgardcooper-louisgiet commented 1 year ago

This is not only an issue for React Native. We're also experiencing this using plain React (in NextJS).

nadetastic commented 1 year ago

@jvgeee I haven't been able to reproduce this issue. Could you try visiting the Hosted UI directly from cognito to be see if its configured correctly there? You can do that by going into the Client App associated with your Cognito user pool.

Hosted UI

Using Auth.federatedSignIn() should do the same thing, so Im hoping to determine if the issue is on the client side or on Cognito side.

nadetastic commented 1 year ago

@edgardcooper-louisgiet @edgardcooper-lukasdemeyere could you also share a bit more details?

edgardcooper-lukasdemeyere commented 1 year ago

We've been using Cognito and Amplify for over a year now, but without federated logins. We are now trying to add Facebook, Google and Apple logins. We started testing with Google.

We configured this in the Cognito UI, however when we run amplify pull our aws-export.js isn't updated. So the oauth property stays empty. After some research, I saw this is only updating when running amplify push. So we configured the federated logins using the CLI amplify auth update and indeed the CLI showed us no federated logins were configured. So we did, we pushed it to the cloud, but our aws-export.js is not being updated. In the UI we see that our user pool is updated by the last edited timestamp. When we now run amplify auth update again, we see Google is configured as a federated login.

We tried to hydrate the oauth property ourselves, following the example provided by @jvgeee, this gives us another error so looks like this is the problem. But somehow we can't generate a new aws-export.js.

Answering your questions:

Package.json

{
  "name": "aws-amplify-test",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "aws-amplify": "^5.2.0",
    "aws-sdk": "^2.1086.0",
    "base-64": "^1.0.0",
    "next": "12.1.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-hook-form": "^7.27.1"
  },
  "devDependencies": {
    "@types/node": "17.0.21",
    "@types/react": "17.0.39",
    "eslint": "8.10.0",
    "eslint-config-next": "12.1.0",
    "typescript": "4.6.2"
  }
}

aws-export.js

/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "eu-west-1",
    "aws_cognito_identity_pool_id": "eu-west-1:0ee769c9-022b-4814-8260-59a6cf6dafc6",
    "aws_cognito_region": "eu-west-1",
    "aws_user_pools_id": "eu-west-1_coiC2N90p",
    "aws_user_pools_web_client_id": "3tlun9rqsh919ca04tvftp65",
    "oauth": {},
    "aws_cognito_username_attributes": [
        "EMAIL"
    ],
    "aws_cognito_social_providers": [],
    "aws_cognito_signup_attributes": [
        "EMAIL"
    ],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [
        "SMS"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": "6",
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ]
};

export default awsmobile;

I'm positive when we can generate the aws-export.js correctly, this would work. But how can we generate this with the newest configuration?

jvgeee commented 1 year ago

@jvgeee I haven't been able to reproduce this issue. Could you try visiting the Hosted UI directly from cognito to be see if its configured correctly there? You can do that by going into the Client App associated with your Cognito user pool.

Hosted UI

Using Auth.federatedSignIn() should do the same thing, so Im hoping to determine if the issue is on the client side or on Cognito side.

Yep, when I view it from inside my Cognito dashboard I can see the hosted UI:

image

If I do amplify pull or amplify pull --appId <myappID> --envName production there are no changes to pull.

jvgeee commented 1 year ago

@nadetastic is there an easy way to uninstall/reinstall Amplify / Auth within an RN project? Wondering if this will fix my problem but don't want to have to re-do all of my AWS permissions, auth callbacks and whatnot. Doesn't seem like this is a common issue so it must be some sort of environment setup problem (works in dev but not release...), so wondering if a reinstall might help.

nadetastic commented 1 year ago

@jvgeee running you can delete the /amplify folder as well as the aws-exports file from a copy of the project (you can do from the same project, but I recommend testing with a backup) and rerun amplify pull to reconnect it to your app. I'm not sure what the issue you are facing can be since this error mainly happens if you aws-exports isn't configured with oauth which you show to have.

nadetastic commented 1 year ago

@edgardcooper-lukasdemeyere I see from your aws-exports that your oauth is an empty object, so the error is most likely coming from that. Can you try the same steps I shared above as well?

  1. Delete /amplify folder and aws-exports from project
  2. Rerun amplify pull to reconfigure you backend
edgardcooper-lukasdemeyere commented 1 year ago

@nadetastic we filled in our oauth object ourselves as all things we tried (including these steps you proposed didn't work). Now when we update the amplify auth, aws-export is being updated. Thanks, this fixed this issue. The error message however is not clear what the root cause of this is.

nadetastic commented 1 year ago

@edgardcooper-lukasdemeyere Glad you were able to get it working. Sounds like there may have been an issue with the CLI after you updated the backend where the exports file wasn't updated.

nadetastic commented 1 year ago

Hi @jvgeee, following up - were you able to get this fixed?

jvgeee commented 1 year ago

@nadetastic No. I've deleted the amplify folder, run amplify pull, and the same issue happens. When I run a debug build of the app on IOS, federated sign in with Google works. When I run a release build on IOS (change schema build configuration from debug to release) it fails.

Have tried a bunch of variations and still can't get it to work. Any ideas?

image
nadetastic commented 1 year ago

@jvgeee One thing that came to mind is I'm not 100% sure if you have amazon-cognito-identity-js added to you project. Can you verify that you have it installed as well? and if not, install this as that is most likely the issue. The previous comment only showed the following:

jvgeee commented 1 year ago

@nadetastic Yep it's

"amazon-cognito-identity-js": "^6.2.0",

Here's the full envinfo:

  System:
    OS: macOS 13.3.1
    CPU: (8) arm64 Apple M1
    Memory: 50.72 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.19.1 - ~/.nvm/versions/node/v16.19.1/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.19.3 - ~/.nvm/versions/node/v16.19.1/bin/npm
    Watchman: 2023.05.22.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 113.0.5672.126
    Safari: 16.4
  npmPackages:
    @babel/core: ^7.20.0 => 7.21.3 (7.21.4)
    @babel/plugin-proposal-decorators: 7.20. => 7.21.0
    @babel/plugin-proposal-optional-catch-binding: 7.16.7 => 7.16.7 (7.18.6)
    @babel/preset-env: ^7.20.0 => 7.20.2
    @babel/runtime: ^7.20.0 => 7.21.0
    @expo-google-fonts/space-grotesk: ^0.2.2 => 0.2.3
    @expo/webpack-config: ^18.0.1 => 18.0.2
    @notifee/react-native: ^7.7.1 => 7.7.1
    @react-native-async-storage/async-storage: ^1.18.1 => 1.18.1
    @react-native-community/cli-platform-ios: ^8.0.2 => 8.0.6 (10.2.1)
    @react-native-community/eslint-config: ^3.2.0 => 3.2.0
    @react-native-community/netinfo: ^9.3.10 => 9.3.10
    @react-native-firebase/analytics: ^17.3.1 => 17.4.0
    @react-native-firebase/app: ^17.3.1 => 17.4.0
    @react-navigation/bottom-tabs: ^6.3.2 => 6.5.7
    @react-navigation/native: ~6.0.1 => 6.0.16
    @react-navigation/native-stack: ^6.0.2 => 6.9.12
    @react-navigation/stack: ~6.2.1 => 6.2.3
    @sentry/react-native: ^5.2.0 => 5.2.0
    @tsconfig/react-native: ^2.0.2 => 2.0.3
    @types/i18n-js: 3.8.2 => 3.8.2
    @types/jest: ^29.2.1 => 29.5.0
    @types/react: ^18.0.24 => 18.0.31 (17.0.55)
    @types/react-native: 0.67.8 => 0.67.8
    @types/react-test-renderer: ^18.0.0 => 18.0.0
    @typescript-eslint/eslint-plugin: 5.28.0 => 5.28.0 (5.57.0)
    @typescript-eslint/parser: 5.28.0 => 5.28.0 (5.57.0)
    ContextAPIMixpanel:  0.0.1
    HelloWorld:  0.0.1
    MixpanelDemo:  0.0.1
    SimpleMixpanel:  0.0.1
    TypingIndicatorExample:  0.0.1
    amazon-cognito-identity-js: ^6.2.0 => 6.2.0
    apisauce: 2.1.5 => 2.1.5
    appcenter: 4.4.5 => 4.4.5
    appcenter-analytics: 4.4.5 => 4.4.5
    appcenter-crashes: 4.4.5 => 4.4.5
    aws-amplify: ^5.2.2 => 5.2.2
    aws-amplify-react-native: ^7.0.2 => 7.0.2
    aws-api-gateway-client: ^0.3.7 => 0.3.7
    aws-sdk: ^2.1328.0 => 2.1345.0
    axios: ^1.3.4 => 1.3.4 (0.26.0, 0.21.4, 0.19.0-beta.1)
    babel-jest: ^29.2.1 => 29.5.0 (26.6.3)
    babel-loader: 8.2.5 => 8.2.5 (8.3.0)
    core-js: ^3.30.1 => 3.30.1 (2.6.12)
    date-fns: ^2.29.2 => 2.29.3
    detox: 19.12.1 => 19.12.1
    detox-expo-helpers: 0.6.0 => 0.6.0
    eslint: ^8.19.0 => 8.37.0
    eslint-config-prettier: 8.5.0 => 8.5.0 (8.8.0)
    eslint-config-standard: 17.0.0 => 17.0.0
    eslint-plugin-import: 2.26.0 => 2.26.0
    eslint-plugin-n: ^15.0.0 => 15.6.1
    eslint-plugin-node: 11.1.0 => 11.1.0
    eslint-plugin-promise: 6.0.0 => 6.0.0
    eslint-plugin-react: 7.30.0 => 7.30.0 (7.32.2)
    eslint-plugin-react-native: 4.0.0 => 4.0.0
    expo: ^48.0.0 => 48.0.9
    expo-application: ~5.1.1 => 5.1.1
    expo-av: ^13.2.1 => 13.2.1
    expo-constants: ~14.2.1 => 14.2.1
    expo-detox-hook: 1.0.10 => 1.0.10
    expo-device: ~5.2.1 => 5.2.1
    expo-file-system: ~15.2.2 => 15.2.2
    expo-font: ~11.1.1 => 11.1.1
    expo-linear-gradient: ~12.1.2 => 12.1.2
    expo-linking: ~4.0.1 => 4.0.1
    expo-localization: ~14.1.1 => 14.1.1
    expo-modules-autolinking: ~1.1.0 => 1.1.2
    expo-modules-core: ~1.2.6 => 1.2.6
    expo-permissions: ^14.1.1 => 14.1.1
    expo-splash-screen: ~0.18.1 => 0.18.1
    expo-status-bar: ~1.4.2 => 1.4.4
    expo-web-browser: ~12.1.1 => 12.1.1
    fbjs-scripts: 3.0.1 => 3.0.1
    firebase: ^9.17.1 => 9.18.0
    firebase/analytics:  undefined ()
    firebase/app:  undefined ()
    firebase/app-check:  undefined ()
    firebase/auth:  undefined ()
    firebase/auth/cordova:  undefined ()
    firebase/auth/react-native:  undefined ()
    firebase/compat:  undefined ()
    firebase/compat/analytics:  undefined ()
    firebase/compat/app:  undefined ()
    firebase/compat/app-check:  undefined ()
    firebase/compat/auth:  undefined ()
    firebase/compat/database:  undefined ()
    firebase/compat/firestore:  undefined ()
    firebase/compat/functions:  undefined ()
    firebase/compat/installations:  undefined ()
    firebase/compat/messaging:  undefined ()
    firebase/compat/performance:  undefined ()
    firebase/compat/remote-config:  undefined ()
    firebase/compat/storage:  undefined ()
    firebase/database:  undefined ()
    firebase/firestore:  undefined ()
    firebase/firestore/lite:  undefined ()
    firebase/functions:  undefined ()
    firebase/installations:  undefined ()
    firebase/messaging:  undefined ()
    firebase/messaging/sw:  undefined ()
    firebase/performance:  undefined ()
    firebase/remote-config:  undefined ()
    firebase/storage:  undefined ()
    i18n-js: 3.9.2 => 3.9.2
    jest: ^29.2.1 => 29.5.0
    jest-circus: 26 => 26.6.3 (29.5.0)
    jest-environment-node: 26 => 26.6.2 (29.5.0)
    jest-expo: ^47.0.0 => 47.0.1
    lodash: ^4.17.21 => 4.17.21
    lottie-react-native: ^5.1.5 => 5.1.5
    metro-react-native-babel-preset: 0.73.9 => 0.73.9 (0.73.8)
    mixpanel-react-native: ^2.2.1 => 2.2.1
    mobx: 6.6.0 => 6.6.0
    mobx-react-lite: 3.4.0 => 3.4.0
    mobx-state-tree: 5.1.5 => 5.1.5
    mocha: 6 => 6.2.3
    patch-package: 6.4.7 => 6.4.7
    postinstall-prepare: 1.0.1 => 1.0.1
    prettier: ^2.4.1 => 2.8.7
    query-string: ^8.1.0 => 8.1.0 (7.1.3, 5.1.1, 6.10.1)
    react: 18.2.0 => 18.2.0 (16.14.0)
    react-devtools-core: 4.24.7 => 4.24.7 (4.27.4)
    react-dom: 18.2.0 => 18.2.0
    react-hook-form: ^7.43.2 => 7.43.8
    react-native: 0.71.7 => 0.71.7
    react-native-bootsplash: ^4.6.0 => 4.6.0
    react-native-canvas: ^0.1.38 => 0.1.38
    react-native-code-push: ^8.0.0 => 8.0.0
    react-native-config: 1.4.12 => 1.4.12
    react-native-gesture-handler: ~2.9.0 => 2.9.0
    react-native-get-random-values: ^1.8.0 => 1.8.0
    react-native-gifted-chat: ^2.0.1 => 2.0.1
    react-native-keyboard-aware-scroll-view: ^0.9.5 => 0.9.5
    react-native-keychain: ^8.1.1 => 8.1.1
    react-native-reanimated: ~2.14.4 => 2.14.4
    react-native-reanimated-carousel: ^3.3.0 => 3.3.0
    react-native-redash: 14.0.4 => 14.0.4
    react-native-render-html: ^6.3.4 => 6.3.4
    react-native-safe-area-context: 4.5.0 => 4.5.0
    react-native-screens: ~3.20.0 => 3.20.0
    react-native-svg: ^13.9.0 => 13.9.0
    react-native-svg-transformer: ^1.0.0 => 1.0.0
    react-native-typing-animation: ^0.1.7 => 0.1.7
    react-native-web: ^0.18.7 => 0.18.12
    react-native-webview: 11.26.0 => 11.26.0
    reactotron-core-client: ^2.8.10 => 2.8.10 (2.8.9)
    reactotron-mst: 3.1.4 => 3.1.4
    reactotron-react-js: ^3.3.7 => 3.3.8
    reactotron-react-native: 5.0.3 => 5.0.3
    regenerator-runtime: ^0.13.4 => 0.13.11 (0.11.1)
    ts-jest: 26 => 26.5.6
    typescript: ^4.9.4 => 4.9.5
    webpack: 4 => 4.46.0 (5.76.3)
    webpack-dev-server: ^3 => 3.11.3 (4.13.1)
  npmGlobalPackages:
    @aws-amplify/cli: 10.8.1
    appcenter-cli: 2.13.6
    aws-sdk: 2.1334.0
    corepack: 0.15.1
    expo-cli: 6.3.2
    npm: 8.19.3
    serverless: 3.28.1

NB that this is a bare React Native project that uses some expo modules, not an Expo managed project, if that affects anything.

jvgeee commented 1 year ago

Also this affects both android and IOS release builds. Both work fine on debug builds.

Don't think I'm doing anything particularly weird with build variants, but my app folder is /app instead of /src. I've set this in the .config/project-config.json file:

{
  "projectName": "AppName",
  "version": "3.1",
  "frontend": "javascript",
  "javascript": {
    "framework": "react-native",
    "config": {
      "SourceDir": "app",
      "DistributionDir": "/",
      "BuildCommand": "npm run-script build",
      "StartCommand": "npm run-script start"
    }
  },
  "providers": [
    "awscloudformation"
  ]
}

Is the error message a clue? [TypeError: Cannot read property 'oauthSignIn' of undefined] => Not sure where this is actually erroring, maybe this issue is relevent? eg

this seems to be the Amplify code that is erroring:

image

oAuthHandler seems to be set here:

image

That references this issue but might not be related: https://github.com/aws-amplify/amplify-js/issues/4388

nadetastic commented 1 year ago

Unfortunately i'm still not able to reproduce this when using the minimum dependencies mentioned in the getting started guide while using the same versions you have, and setting my project to use /app instead of /src

Would you be able to share a repo of your project so I can try reproducing with it?

jvgeee commented 1 year ago

@nadetastic Yep sure, I've made a duplicate repo and added you as a contributor. Repo will have to be private though, that ok?

The original boilerplate for this app was using Ignite: https://github.com/infinitered/ignite

Dunno if you'll have trouble doing builds as the XCode profiles are set to my account. Android might be easier (this is a cross-platform issue, so debug builds work on both Android and IOS and release builds fail)

Look for the SocialSignIn component, as well as the user.authSocialSignIn in ./app/models/User.ts.

jvgeee commented 1 year ago

@nadetastic Hey Dan, have you had a chance to look at the repo?

nadetastic commented 1 year ago

Hi @jvgeee, I have been looking at reproducing with your repo but haven't been able to get it quite working yet. Also as an FYI, i did manage to get a simple app working (here) using Ignite's boilerplate and I am able to federate with google successfully.

What this means is that there maybe something specific with you app that is potentially causing this. I'll investigate a bit more and follow up with my findings (whether I get it working or not)

One question I did have is have you tried launching the app in production via the React Native CLI (npm react-native run ios --mode Release) ?

jvgeee commented 1 year ago

Just rebuilt the app on top of a fresh Ignite release, try pulling it and then try npx react-native run-ios --mode Release.

nadetastic commented 1 year ago

Following up here @jvgeee - I've spent a bit of time working on this and I noticed that the URL Opener config you have is for expo applications. Have you tried building your App with Expo and faced this issue?

Also to rule it out I would recommend disabling the urlOpener that is passed to Amplify.configure() then build your app and try to sign in with Google. This should open the external browser instead.

Additionally, if you are not building your app with Expo, then I recommend configuring your urlOpener for React Native using react-native-inappbrowser-reborn instead of how you have it - for Expo with expo-web-browser.

import InAppBrowser from 'react-native-inappbrowser-reborn';

async function urlOpener(url, redirectUrl) {
  await InAppBrowser.isAvailable();
  const { type, url: newUrl } = await InAppBrowser.openAuth(url, redirectUrl, {
    showTitle: false,
    enableUrlBarHiding: true,
    enableDefaultShare: false,
    ephemeralWebSession: false,
  });

  if (type === 'success') {
    Linking.openURL(newUrl);
  }
}

Amplify.configure({
  ...awsconfig,
  oauth: {
    ...awsconfig.oauth,
    urlOpener,
  },
});
nadetastic commented 9 months ago

HI @jvgeee following up here - let me know if you were able to get this resolved or if the above comment helped you in addressing this issue.

jvgeee commented 9 months ago

@nadetastic Unfortunately no it didn't. Feels like maybe there's something wrong with my Amplify setup itself if you were unable to replicate it.

powellrw commented 9 months ago

@jvgeee I just ran into this error and have a suggestion. If you are using config vars or environment secrets of some kind to specify the redirect URL (to override multiple entries as we are told to), take a look and see if it is specified correctly for your release build setup. If it is not, it would cause precisely this error to occur in only your release builds.

In my case it was the opposite, my dev build suddenly stopped working with this error. Turned out my .env file was not being picked up by expo, as I had earlier run the app without the .env and the cache never looked for a new one.

ctoxyz commented 8 months ago

exploring Amplify > Im stuck on this exact same issue - first it functioned to login > then signout produced the error > then sign-in started failing (no changes) - rebuilt the entire thing again - same thing

nadetastic commented 7 months ago

Hi @jvgeee following up here - are you still facing this issue, specifically have you tried to use it with the latest version (aws-amplify@6.x.x) of the library?

Matsukii commented 6 months ago

Hi had that for days and came to what can be the fix aws-amplify@5.3

I did got rid of "oauthsignin" but then error "redirectsigin" shown I debugged the code and even setting aws exports in main.js (I"m on Vue3, js) and found that the this and _config arent set from main, I had to import inside my login component both the aws-exports and use Amplify configure. this sets the _config but isnt enough, he Auth class is trying use awsmobie.oauth {} }while amplify sets it to awsmobile.Auth.Cognito.login... .oauth

### TL;DR: use amplify then open aws-exports, duplicate Cognito, move to top, rename. example below

fix

debug

  1. import Auth, amplify
  2. configure
  3. add to window
  4. create fn on window to call Sigin... () and call it to get stack

const awsmobile = {
    "userPoolClientId": "x",
    "region": "us-east-1",
    "userPoolId": "s-east-x",
    "userPoolWebClientId": "x",
    "identityPoolId": "us-east-1:3x",
    "aws_project_region": "us-east-1",
    "aws_cognito_region": "us-east-1",
    "aws_user_pools_id": "us-east-x",
    "aws_user_pools_web_client_id": "x",
    "aws_project_region": "us-east-1",
    "aws_cognito_username_attributes": [],
    "aws_cognito_social_providers": ["google"],
    "aws_cognito_signup_attributes": [
        "UPDATED_AT"
    ],
    "aws_cognito_mfa_configuration": "OPTIONAL",
    "aws_cognito_mfa_types": [
        "SMS",
        "TOTP"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": [
            "REQUIRES_LOWERCASE",
            "REQUIRES_UPPERCASE",
            "REQUIRES_NUMBERS",
            "REQUIRES_SYMBOLS"
        ]
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL",
        "PHONE_NUMBER"
    ],
    "Auth": {
        "Cognito": {
            "userPoolClientId": "x",
            "region": "us-east-1",
            "userPoolId": "s-east-x",
            "userPoolWebClientId": "x",
            "identityPoolId": "us-east-1:3x6",
            "aws_project_region": "us-east-1",
            "aws_cognito_region": "us-east-1",
            "aws_user_pools_id": "us-east-1_jTrm8n2fY",
            "aws_user_pools_web_client_id": "x",
            "loginWith": {
                "oauth": {
                    "domain": "auth.x.com",
                    "scopes": [
                        "email",
                        "openid"
                    ],
                    "redirectSignIn": [
                        "https://auth.x.com",
                        "http://localhost:8080",

                    ],
                    "redirectSignOut": [
                        "https://x.com"
                    ],
                    "responseType": "token"
                }
            }
        }
    },
    "oauth": {
        "userPoolClientId": "x",
        "region": "us-east-1",
        "userPoolId": "s-east-x",
        "userPoolWebClientId": "x",
        "identityPoolId": "us-east-1:x",
        "aws_project_region": "us-east-1",
        "aws_cognito_region": "us-east-1",
        "aws_user_pools_id": "us-east-d",
        "aws_user_pools_web_client_id": "",
                "domain": "auth.d.com",
                "scopes": [
                    "email",
                    "openid"
                ],
                "redirectSignIn": [
                    // "https://auth.d.com",
                    "http://localhost:8080",

                ],
                "redirectSignOut": [
                    "https://d.com"
                ],
                "responseType": "token"
    }
};

export default awsmobile;
jvgeee commented 6 months ago

@nadetastic FYI I've tried this on the new V6 of Amplify and it works now! Phew.

jaronkk commented 1 month ago

In case this helps anyone, I was encountering this exact issue (TypeError: Cannot read properties of undefined (reading 'oauthSignIn')) but managed to resolve it.

I discovered that the aws-exports.js file was not including the redirectSignIn and redirectSignOut urls when my only configured callback and sign-out urls were for localhost. (under the user pool -> App Integration -> App client -> Hosted UI)

    "domain": "<my-domain>.auth.us-east-1.amazoncognito.com",
    "responseType": "code",
    "scope": [
      "email",
      "openid"
    ],
    "redirectSignOut": null
  },

As soon as I added a non-localhost domain and ran amplify pull the oauth config started including the redirectSignIn and redirectSignOut urls and I was able to complete the sign in flow.