amplify-js: Oauth Social login success but cannot authenticated user

Before opening, please confirm:

JavaScript Framework

Next.js

Amplify APIs

GraphQL API

Amplify Categories

auth

Environment information

# Put output below this line


  System:
    OS: macOS 11.4
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 797.84 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 15.5.1 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.3.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 92.0.4515.131
    Safari: 14.1.1
  npmPackages:
    @ampproject/toolbox-optimizer:  undefined ()
    @aws-amplify/cli: ^5.1.2 => 5.1.2 
    @babel/core:  undefined ()
    @babel/plugin-proposal-class-properties: ^7.13.0 => 7.13.0 (7.14.5)
    @babel/plugin-proposal-decorators: ^7.13.15 => 7.13.15 
    @emotion/babel-plugin: ^11.2.0 => 11.2.0 (11.3.0)
    @emotion/core: ^11.0.0 => 11.0.0 (10.1.1)
    @emotion/react: ^11.1.5 => 11.1.5 
    @emotion/styled: ^11.3.0 => 11.3.0 
    @types/node: ^14.14.37 => 14.14.37 (12.20.15, 14.14.41)
    @types/react: ^17.0.3 => 17.0.3 
    @types/react-cookies: ^0.1.0 => 0.1.0 
    @types/uuid: ^8.3.0 => 8.3.0 
    @typescript-eslint/eslint-plugin: ^4.19.0 => 4.19.0 
    amphtml-validator:  undefined ()
    arg:  undefined ()
    async-retry:  undefined ()
    async-sema:  undefined ()
    aws-amplify: ^4.2.1 => 4.2.1 
    babel-plugin-transform-typescript-metadata: ^0.3.2 => 0.3.2 
    bfj:  undefined ()
    cacache:  undefined ()
    cache-loader:  undefined ()
    ci-info:  undefined ()
    comment-json:  undefined ()
    compression:  undefined ()
    conf:  undefined ()
    content-type:  undefined ()
    cookie:  undefined ()
    cookie-cutter: ^0.2.0 => 0.2.0 
    core-decorators: ^0.20.0 => 0.20.0 
    css-loader:  undefined ()
    debug:  undefined ()
    devalue:  undefined ()
    emotion: ^11.0.0 => 11.0.0 
    escape-string-regexp:  undefined ()
    eslint: 7.2.0 => 7.2.0 (7.23.0)
    eslint-config-airbnb-typescript: ^12.3.1 => 12.3.1 
    eslint-config-prettier: ^8.1.0 => 8.1.0 
    eslint-import-resolver-typescript: ^2.4.0 => 2.4.0 
    eslint-plugin-import: 2.22.1 => 2.22.1 
    eslint-plugin-jsx-a11y: 6.4.1 => 6.4.1 
    eslint-plugin-prettier: ^3.3.1 => 3.3.1 
    eslint-plugin-react: 7.21.5 => 7.21.5 
    eslint-plugin-react-hooks: ^4.2.0 => 4.2.0 
    file-loader:  undefined ()
    find-cache-dir:  undefined ()
    find-up:  undefined ()
    formik: ^2.2.9 => 2.2.9 
    fresh:  undefined ()
    global: ^4.4.0 => 4.4.0 
    gzip-size:  undefined ()
    http-proxy:  undefined ()
    ignore-loader:  undefined ()
    is-animated:  undefined ()
    is-docker:  undefined ()
    is-wsl:  undefined ()
    json5:  undefined ()
    jsonwebtoken:  undefined ()
    loader-utils:  undefined ()
    lodash.curry:  undefined ()
    lru-cache:  undefined ()
    memo-parser:  0.2.1 
    mobx: ^6.2.0 => 6.2.0 
    mobx-react: ^7.2.0 => 7.2.0 
    nanoid:  undefined ()
    neo-async:  undefined ()
    new-plugin-package:  1.0.0 
    next: ^10.0.9 => 10.0.9 
    next-cookies: ^2.0.3 => 2.0.3 
    ora:  undefined ()
    postcss-flexbugs-fixes:  undefined ()
    postcss-loader:  undefined ()
    postcss-preset-env:  undefined ()
    postcss-scss:  undefined ()
    prettier: ^2.2.1 => 2.2.1 (1.19.1)
    prettier-eslint: ^12.0.0 => 12.0.0 
    react: ^17.0.2 => 17.0.2 
    react-cookie: ^4.0.3 => 4.0.3 
    react-dom: ^17.0.2 => 17.0.2 
    react-helmet: ^6.1.0 => 6.1.0 
    react-messenger-customer-chat: ^0.8.0 => 0.8.0 
    react-script-tag: ^1.1.2 => 1.1.2 
    react-select: ^4.3.0 => 4.3.0 
    react-slick: ^0.28.1 => 0.28.1 
    react-toast-notifications: ^2.4.3 => 2.4.3 
    recast:  undefined ()
    reflect-metadata: ^0.1.13 => 0.1.13 
    remove: ^0.1.5 => 0.1.5 
    resolve-url-loader:  undefined ()
    sass-loader:  undefined ()
    schema-utils:  undefined ()
    semver:  undefined ()
    send:  undefined ()
    slick-carousel: ^1.8.1 => 1.8.1 
    source-map:  undefined ()
    string-hash:  undefined ()
    strip-ansi:  undefined ()
    stylelint: ^13.12.0 => 13.12.0 
    stylelint-config-standard: ^21.0.0 => 21.0.0 
    stylelint-config-styled-components: ^0.1.1 => 0.1.1 
    stylelint-order: ^4.1.0 => 4.1.0 
    stylelint-processor-styled-components: ^1.10.0 => 1.10.0 
    stylelint-scss: ^3.19.0 => 3.19.0 
    terser:  undefined ()
    text-table:  undefined ()
    thread-loader:  undefined ()
    typescript: ^4.2.3 => 4.2.3 (3.9.10, 3.9.9)
    unistore:  undefined ()
    url-loader: ^4.1.1 => 4.1.1 
    web-vitals:  undefined ()
    webpack:  undefined ()
    webpack-sources:  undefined ()
    yup: ^0.32.9 => 0.32.9 
    zen-observable: ^0.8.15 => 0.8.15 (0.7.1)
  npmGlobalPackages:
    @aws-amplify/cli: 4.41.0
    npm: 7.3.0
    yarn: 1.22.10

</details>


### Describe the bug

Although oauth social login is successful and user information is put into userpool,"Uncaught (in promise) The user is not authenticated" error occurs.

Facebook is redirected to https://www.tintinlive.vn/#_=_.

Google is redirected to https://tintinlive/#.

### Expected behavior

User authentication and login must be successful with the redirection link running correctly.


### Reproduction steps

On the login page, click each social login button and go home through the redirection link.


### Code Snippet

```javascript
// Put your code below this line.


  function loginWithGoogle() {
    Auth.federatedSignIn({ provider: CognitoHostedUIIdentityProvider.Google });
    setCookie('socialUser', 'social');
  }

  function loginWithFacebook() {
    Auth.federatedSignIn({ provider: CognitoHostedUIIdentityProvider.Facebook });
    setCookie('socialUser', 'social');
  }


 <>
      <FormWrapper name='form' onSubmit={formik.handleSubmit}>
        <Self>
          <Layout>
            <SocialBlock>
              <FacebookDiv onClick={loginWithFacebook}>
                <SocialFacebook />
                <SocialTextFacebook>Login with Facebook</SocialTextFacebook>
              </FacebookDiv>
              <GoogleDiv onClick={loginWithGoogle}>
                <SocialGoogle />
                <SocialTextGoogle>Login with Google</SocialTextGoogle>
              </GoogleDiv>
            </SocialBlock>
          </Layout>
        </Self>


    </>
  );

### Log output

<details>

// Put your logs below this line

Uncaught (in promise) The user is not authenticated

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-northeast-2”, “aws_cognito_identity_pool_id”: “ap-northeast-2:e12b4f97-77b9-4f30-be89-f69b21abed29”, “aws_cognito_region”: “ap-northeast-2”, “aws_user_pools_id”: “ap-northeast-2_TaAG9EBUR”, “aws_user_pools_web_client_id”: “5il68icuso99k6fqpk17vqsfol”, “oauth”: { “domain”: “fined256c73b-d256c73b-main.auth.ap-northeast-2.amazoncognito.com”, “scope”: [ “phone”, “email”, “openid”, “profile”, “aws.cognito.signin.user.admin” ], “redirectSignIn”: “https://tintinlive.vn/”, “redirectSignOut”: “https://tintinlive.vn/”, “responseType”: “code” }, “federationTarget”: “COGNITO_USER_POOLS”, “aws_user_files_s3_bucket”: “finef05006faa82440a6bcdd7a319adcaa4b181850-main”, “aws_user_files_s3_bucket_region”: “ap-northeast-2”, “aws_appsync_graphqlEndpoint”: “https://4ehcsu663zcl7bqu6pf4i3s6km.appsync-api.ap-northeast-2.amazonaws.com/graphql”, “aws_appsync_region”: “ap-northeast-2”, “aws_appsync_authenticationType”: “API_KEY”, “aws_appsync_apiKey”: “da2-rndd4gesqjfuvgkid6ommgnody”, “aws_cloud_logic_custom”: [ { “name”: “AdminQueries”, “endpoint”: “https://5oy84n7aof.execute-api.ap-northeast-2.amazonaws.com/main”, “region”: “ap-northeast-2” } ] };

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 34 (18 by maintainers)

Most upvoted comments

@seunghwako you should add this line above your amplify configuration and see what error you’re getting from Auth after being redirected from Google during oauth flow. I’m still not exactly sure what the cause of the issue might be for you and this may help us find out.

Amplify.Logger.LOG_LEVEL = "DEBUG"

@chrisbonifacio

The way I created my hosted zone in Route 53 was to migrate the dns service from my domain in Godaddy to Route 53, which is basically make the Godaddy DNS name servers to point to the ones in AWS Route 53. Similarly to the guide below.

https://virtualizationreview.com/articles/2020/07/14/migrating-dns-services-aws.aspx

After I created my hosted zone in Route 53, I used the steps you mentioned about adding a domain, which is really easy because since you have already a hosted zone, you just need to selected when you want to add the domain and everything is setup really easy.

PS: About the screenshot I will post it in another post

HI! @chrisbonifacio. I provide the amplify auth’s parameter.json code, amplify auth signin document customizing code and Our Rendering code! Thanks! Current env is main But I change env to dev, It works well. The difference between the two environments is only the difference between redirection link being local or not.

amplify/auth/fined0f28391/parametet.json { "identityPoolName": "fined0f28391_identitypool_d0f28391", "allowUnauthenticatedIdentities": true, "resourceNameTruncated": "fined0f28391", "userPoolName": "fined0f28391_userpool_d0f28391", "autoVerifiedAttributes": [ "email" ], "mfaConfiguration": "OFF", "mfaTypes": [ "SMS Text Message" ], "smsAuthenticationMessage": "Your authentication code is {####}", "smsVerificationMessage": "Your verification code is {####}", "emailVerificationSubject": "Your verification code", "emailVerificationMessage": "Your verification code is {####}", "defaultPasswordPolicy": false, "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [], "requiredAttributes": [ "email" ], "userpoolClientGenerateSecret": true, "userpoolClientRefreshTokenValidity": 30, "userpoolClientWriteAttributes": [ "email" ], "userpoolClientReadAttributes": [ "email" ], "userpoolClientLambdaRole": "fined0d0f28391_userpoolclient_lambda_role", "userpoolClientSetAttributes": false, "sharedId": "d0f28391", "resourceName": "fined0f28391", "authSelections": "identityPoolAndUserPool", "authRoleArn": { "Fn::GetAtt": [ "AuthRole", "Arn" ] }, "unauthRoleArn": { "Fn::GetAtt": [ "UnauthRole", "Arn" ] }, "useDefault": "defaultSocial", "hostedUI": true, "userPoolGroupList": [ "admin", "admin" ], "serviceName": "Cognito", "dependsOn": [], "hostedUIDomainName": "fined256c73b-d256c73b", "authProvidersUserPool": [ "Facebook", "Google" ], "hostedUIProviderMeta": "[{\"ProviderName\":\"Facebook\",\"authorize_scopes\":\"email,public_profile\",\"AttributeMapping\":{\"email\":\"email\",\"username\":\"id\"}},{\"ProviderName\":\"Google\",\"authorize_scopes\":\"openid email profile\",\"AttributeMapping\":{\"email\":\"email\",\"username\":\"sub\"}}]", "oAuthMetadata": "{\"AllowedOAuthFlows\":[\"code\"],\"AllowedOAuthScopes\":[\"phone\",\"email\",\"openid\",\"profile\",\"aws.cognito.signin.user.admin\"],\"CallbackURLs\":[\"https://tintinlive.com/\"],\"LogoutURLs\":[\"https://tintinlive.com/\"]}" }

`import { CognitoHostedUIIdentityProvider } from '@aws-amplify/auth/lib/types';
import styled from '@emotion/styled';
import { Auth, Hub } from 'aws-amplify';
.
.
.
.
.
.
function loginWithGoogle() {
    Auth.federatedSignIn({ provider: CognitoHostedUIIdentityProvider.Google });
    setCookie('socialUser', 'social');
  }

  function loginWithFacebook() {
    Auth.federatedSignIn({ provider: CognitoHostedUIIdentityProvider.Facebook });
    setCookie('socialUser', 'social');
  }

return(
<SocialBlock>
              <FacebookDiv onClick={loginWithFacebook}>
                <SocialFacebook />
                <SocialTextFacebook>Login with Facebook</SocialTextFacebook>
              </FacebookDiv>
              <GoogleDiv onClick={loginWithGoogle}>
                <SocialGoogle />
                <SocialTextGoogle>Login with Google</SocialTextGoogle>
              </GoogleDiv>
            </SocialBlock>
);`

pages/api/signin.tsx

`/* eslint-disable no-console */
import { Auth } from 'aws-amplify';

const Signin = async (username, password) => {
  try {
    await Auth.signIn(username, password);
    const user = await Auth.currentAuthenticatedUser();
    const {
      signInUserSession: { idToken },
    } = user;
    return idToken;
  } catch (error) {
    console.log('error: ', error);
    switch (error.code) {
      case 'NetworkError':
        console.log('error1: ', error);
        // 네트워크에러가 발생했습니다.
        return 'Unknown';
      case 'NotAuthorizedException':
        console.log('error2: ', error);
        // 아이디나 비밀번호가 다릅니다.
        return 'Unknown';
      case 'UserNotConfirmedException':
        console.log('error3: ', error);
        // 이메일에서 인증코드를 확인 후 등록해주세요.
        return 'Unknown';
      case 'UserNotFoundException':
        console.log('error4: ', error);
        // 가입자 정보가 존재하지 않습니다.
        return 'Unknown';
      default:
        return 'Unknown';
    }
  }
};

export default Signin;`