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.42k stars 2.12k forks source link

Auth.federatedSignIn - `TypeError: undefined is not an object (evaluating 'this._oAuthHandler.oauthSignIn')` #8220

Closed alexung closed 3 years ago

alexung commented 3 years 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 11.3 CPU: (4) x64 Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz Memory: 55.48 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 15.0.1 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.0.3 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Browsers: Chrome: 90.0.4430.93 Safari: 14.1 npmPackages: @babel/core: ^7.6.2 => 7.7.7 @babel/runtime: ^7.6.2 => 7.13.10 @bam.tech/react-native-make: ^3.0.0 => 3.0.0 @emotion/core: ^10.0.27 => 10.0.27 @emotion/native: ^10.0.27 => 10.0.27 @react-native-community/cli-platform-ios: 3.0.0 => 3.0.0 @react-native-community/eslint-config: ^0.0.5 => 0.0.5 @react-native-community/masked-view: ^0.1.6 => 0.1.6 @react-native-community/netinfo: ^5.6.2 => 5.6.2 @react-navigation/bottom-tabs: ^5.1.0 => 5.1.0 @react-navigation/native: ^5.0.8 => 5.0.8 (3.6.2) @react-navigation/stack: ^5.1.0 => 5.1.0 @testing-library/react-native: ^7.0.2 => 7.0.2 @types/jest: ^24.0.24 => 24.0.25 @types/react-native: ^0.60.25 => 0.60.28 @types/react-test-renderer: 16.9.1 => 16.9.1 @typescript-eslint/eslint-plugin: ^2.12.0 => 2.15.0 (1.13.0) @typescript-eslint/parser: ^2.12.0 => 2.15.0 (1.13.0) HelloWorld: 0.0.1 Sample: 0.0.1 ViewOverflowExample: 0.0.1 amazon-cognito-identity-js: ^4.5.8 => 4.5.8 (4.5.4) aws-amplify: 3.3.8 => 3.3.8 babel-jest: ^24.9.0 => 24.9.0 babel-plugin-module-resolver: ^4.0.0 => 4.0.0 (3.2.0) eslint: ^6.5.1 => 6.8.0 (7.23.0) expo: ^36.0.2 => 36.0.2 hermes-inspector-msggen: 1.0.0 jest: ^24.9.0 => 24.9.0 metro-react-native-babel-preset: ^0.56.0 => 0.56.4 prop-types: ^15.7.2 => 15.7.2 (15.5.10) react: 16.9.0 => 16.9.0 react-animated: 0.1.0 react-native: 0.61.5 => 0.61.5 react-native-deck-swiper: ^1.6.7 => 1.6.7 react-native-elements: ^1.2.7 => 1.2.7 react-native-gesture-handler: ^1.5.3 => 1.5.3 react-native-iap: 4.6.3 => 4.6.3 react-native-in-app-review: ^3.1.1 => 3.1.1 react-native-inappbrowser-reborn: ^3.5.1 => 3.5.1 react-native-linear-gradient: ^2.5.6 => 2.5.6 react-native-modal: ^11.5.6 => 11.5.6 react-native-reanimated: ^1.7.0 => 1.7.0 react-native-safe-area-context: ^0.6.2 => 0.6.2 react-native-screens: ^2.0.0-alpha.31 => 2.0.0-alpha.31 (1.0.0-alpha.23) react-native-shimmer-placeholder: ^1.0.36 => 1.0.36 react-native-splash-screen: ^3.2.0 => 3.2.0 react-native-stack: ^1.0.0-alpha11 => 1.0.0-alpha11 react-native-typescript-transformer: ^1.2.13 => 1.2.13 react-native-vector-icons: ^6.6.0 => 6.6.0 react-native-view-overflow: ^0.0.4 => 0.0.4 react-navigation: ^4.0.10 => 4.0.10 react-navigation-stack: ^2.0.16 => 2.0.16 react-query: ^3.13.0 => 3.13.0 react-test-renderer: 16.9.0 => 16.9.0 typescript: ^3.7.3 => 3.7.4 npmGlobalPackages: @aws-amplify/cli: 4.45.1 application-name: 0.0.1 aws-sdk: 2.49.0 awsmobile-cli: 1.1.7 bower: 1.8.0 browserify-incremental: 3.1.1 chai: 3.5.0 copy-dynamodb-table: 2.0.20 create-react-app: 2.1.8 create-react-native-app: 1.0.0 d3-dsv: 1.0.5 dotenv: 8.0.0 expo-cli: 3.11.7 express-generator: 4.12.1 express: 4.12.3 gatsby-cli: 2.6.4 gatsby: 2.24.85 generator-rn-toolbox: 3.14.0 gulp: 3.9.1 http-server: 0.8.0 jasmine: 3.1.0 json: 9.0.1 mocha: 2.4.5 next: 8.1.0 node-sass: 5.0.0 nodemon: 1.11.0 npm-check-updates: 2.14.2 npm-install-peers: 1.2.1 npm-run-all: 4.1.3 npm: 7.0.3 prisma: 1.32.2 react-native-cli: 2.0.1 react-native: 0.63.4 react: 16.13.1 serverless: 1.23.0 sharp-cli: 1.13.1 sharp: 0.28.1 ts-node: 8.3.0 typescript: 3.5.3 wach: 0.10.1 webpack: 2.5.1 yo: 3.1.1 ```

Describe the bug

Users when clicking the oauth button, e.g. below...

<Button
  onPress={() =>
           Auth.federatedSignIn({
              provider: CognitoHostedUIIdentityProvider.Google,
            }).catch(federatedSignInError => {
              console.log({ federatedSignInError });
              throw new Error(federatedSignInError);
            })
  }
/>

...are getting TypeError: undefined is not an object (evaluating 'this._oAuthHandler.oauthSignIn').

What's strange is that In aws-exports.js the oauth object is empty. Not sure exactly why, given that this file is git-ignored and for the past year I've been using federatedSignIn with google/apple?:

const awsmobile = {
    ...
    "oauth": {},
   ...
};

I think what had happened is that my aws-exports.js, on some amplify push removed all oauth data. Given that this file is git-ignored, I'm unable to get it back. Do you all know how to retrieve this information again, given that I haven't made any changes in the aws console?

Thank you for your help.

Expected behavior

  1. User clicks federatedSignIn button
  2. New inapp browser window pops up allowing user to oauth in with said button to sign in
  3. User can sign in

Reproduction steps

With amplify of any minor/patch version in v3.3.x:

  1. User clicks federatedSignIn button
  2. Error comes up saying TypeError: undefined is not an object (evaluating 'this._oAuthHandler.oauthSignIn')
  3. No window is opened for user to continue oauth process
Screen Shot 2021-05-04 at 1 58 18 PM

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

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

nickarocho commented 3 years ago

Hi @alexung sorry to hear you are having issues retrieving the oauth data you once had in your aws-exports.js file. It indeed can be problematic since it is usually git ignored.

Have you tried running amplify pull from the root of your project directory? I just opened one of my sample apps locally, deleted the aws-exports.js contents, ran that command, and it pulled in the original data.

If that doesn't work, something else is likely happening with your oauth configuration. But let us know if the amplify pull command does the trick, and if not we can go back to the drawing board together!

chrisbonifacio commented 3 years ago

Closing this issue for now as we have not heard back from you. Please feel free to re-open this if you are still in need of assistance. Thank you!

ShepSims commented 2 years ago

Hi! I am getting the same error, and was wondering if you were ever able to reproduce it.

Similar to Op, my oauth is empty in aws-exports.js and I know it shouldn't be. When I amplify pull, it does not bring the data back in.

Unlike op, I can fix it manually because I have copy/pasted the correct aws-exports before, so had it handy.

If I manually change aws-exports.js to the correct config as below it works flawlessly, but amplify pulling resets the file to the incorrect config. (***** used in place of app-specific keys)

// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten. const awsmobile = { aws_project_region: 'us-west-2', aws_cognito_identity_pool_id: 'us-west-2:', aws_cognito_region: 'us-west-2', aws_user_poolsid: 'us-west-2', aws_user_pools_web_client_id: '', oauth: { domain: '.auth.us-west-2.amazoncognito.com', scope: ['aws.cognito.signin.user.admin', 'email', 'openid', 'phone', 'profile'], redirectSignIn: 'exp://127.0.0.1:19000/', redirectSignOut: 'exp://127.0.0.1:19000/', responseType: 'code', }, federationTarget: 'COGNITO_USER_POOLS', aws_appsync_graphqlEndpoint: 'https://*****.appsync-api.us-west-2.amazonaws.com/graphql', aws_appsync_region: 'us-west-2', aws_appsync_authenticationType: 'API_KEY', aws_appsync_apiKey: '*****', }; export default awsmobile;

The following is the incorrect config that is produced from an amplify pull.

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

const awsmobile = { "aws_project_region": "us-west-2", "aws_cognito_identity_pool_id": "us-west-2:", "aws_cognito_region": "us-west-2", "aws_user_poolsid": "us-west-2", "aws_user_pools_web_client_id": "", "oauth": {}, "aws_appsync_graphqlEndpoint": "https://.appsync-api.us-west-2.amazonaws.com/graphql", "aws_appsync_region": "us-west-2", "aws_appsync_authenticationType": "API_KEY", "aws_appsync_apiKey": "*****" };

export default awsmobile;

Since we amplify env checkout and amplify pull to switch branches all the time, this is a huge pain in the neck and I would love to know how to fix it. Any help would be amazing!

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.