amplify-js
amplify-js copied to clipboard
Getting "no current user" error after redirect from Cognito Hosted UI
Before opening, please confirm:
- [X] I have searched for duplicate or closed issues and discussions.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
System: OS: macOS 10.15.5 CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 1.86 GB / 32.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 17.9.0 - /usr/local/bin/node Yarn: 1.22.18 - /usr/local/bin/yarn npm: 8.5.5 - /usr/local/bin/npm Browsers: Brave Browser: 93.1.29.79 Chrome: 101.0.4951.64 Firefox: 99.0.1 Safari: 13.1.1 npmPackages: @testing-library/jest-dom: ^5.16.4 => 5.16.4 @testing-library/react: ^13.1.1 => 13.1.1 @testing-library/user-event: ^13.5.0 => 13.5.0 aws-amplify: ^4.3.18 => 4.3.22 react: ^18.1.0 => 18.1.0 react-dom: ^18.1.0 => 18.1.0 react-router-dom: ^6.3.0 => 6.3.0 react-scripts: 5.0.1 => 5.0.1 web-vitals: ^2.1.4 => 2.1.4 npmGlobalPackages: @aws-amplify/cli: 4.18.0 eslint: 7.1.0 firebase-tools: 8.1.1 gulp-cli: 2.2.1 jest: 25.1.0 knex: 0.20.8 npm: 8.5.5 ts-node: 8.6.2 typescript: 3.7.4
Describe the bug
Hi there, I am trying to learn authentication code grant flow with Cognito Hosted UI. Everything seems working until I get redirected back to my protected page. All the /authorize, /login and /token calls are getting completed successfully. I can also confirm that I see the URL with /code parameter generated which is then redirected again. As the final step when I use await Auth.currentAuthenticatedUser(); I get an error with "no current user". So, if I am not mistaken Amplify handles all the required OAUTH calls internally which I would then expect to get an authorized user at the end. I found a similar issue from #7742 and I added cookieStorage object with secure flag set to false but it didn't work as well.
Here I also attached a screenshot to show all the related oauth calls are ending with success.

Expected behavior
Getting a successfull response from Auth.currentAuthenticatedUser() function call.
Reproduction steps
See attached code.
Code Snippet
App.js
import './App.css';
import React from 'react'
import Amplify from 'aws-amplify';
Amplify.configure({
Auth: {
// REQUIRED - Amazon Cognito Region
region: 'us-east-1',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: process.env.REACT_APP_USERPOOL_ID,
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: process.env.REACT_APP_USERPOOL_WEB_CLIENT_ID,
// OPTIONAL - Enforce user authentication prior to accessing AWS resources or not
mandatorySignIn: false,
// OPTIONAL - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
authenticationFlowType: 'USER_PASSWORD_AUTH',
// OPTIONAL - Hosted UI configuration
oauth: {
domain: 'belttgvsdu.auth.us-east-1.amazoncognito.com',
scope: ['myresourceserver/awesomeapi.read', 'myresourceserver/awesomeapi.write'],
redirectSignIn: 'http://localhost:3000/dashboard',
redirectSignOut: 'http://localhost:3000',
responseType: 'code'
}
}
});
function App(props) {
return (
<div className="App">
<h1>This is Landing page</h1>
<a href="https://belttgvsdu.auth.us-east-1.amazoncognito.com/oauth2/authorize?client_id=3chm4jkbcn767oqu2m9icconcs&response_type=code&scope=myresourceserver%2Fawesomeapi.read+myresourceserver%2Fawesomeapi.write&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fdashboard">Login</a>
</div>
);
}
export default App;
And here is the dashboard.js to render localhost:3000/dashboard
import React, {useEffect, useState} from 'react';
import '../App.css';
import {Auth} from 'aws-amplify';
import {Navigate} from "react-router-dom";
function Dashboard(props) {
const [user, setUser] = useState();
const [isLoading, setIsLoading] = useState(true);
async function getCurrentUser() {
try {
const authUser = await Auth.currentAuthenticatedUser();
console.log(JSON.stringify(authUser));
setUser(authUser);
} catch (e) {
console.log('error happened', e);
setUser(null);
setIsLoading(false);
}
}
useEffect(() => {
getCurrentUser();
}, []);
async function handleSignOut(event) {
event.preventDefault();
try {
await Auth.signOut();
} catch (error) {
console.log('error signing out: ', error);
}
setUser(null);
setIsLoading(false);
}
if (!user && !isLoading) {
return <Navigate to="/" replace={true} />
}
return (
<div className="container">
<h1>Dashboard</h1>
<button onClick={handleSignOut} className="fluid ui button blue">Sign Out</button>
</div>
)
}
export default Dashboard;
Log output
[DEBUG] 46:04.595 Amplify - amplify config
Object { Auth: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.599 AuthClass - configure Auth [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.599 Parser - parse config
Array(3) [ {…}, "to amplifyconfig", {…} ]
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.599 Hub - Dispatching to auth with
Object { event: "parsingCallbackUrl", data: {…}, message: "The callback url is being parsed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.600 Hub - Dispatching to auth with
Object { event: "parsingCallbackUrl", data: {…}, message: "The callback url is being parsed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.600 AnalyticsClass - on hub capsule auth
Object { event: "parsingCallbackUrl", data: {…}, message: "The callback url is being parsed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.600 Hub - Dispatching to auth with
Object { event: "parsingCallbackUrl", data: {…}, message: "The callback url is being parsed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.600 Hub - Dispatching to auth with
Object { event: "parsingCallbackUrl", data: {…}, message: "The callback url is being parsed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.601 OAuth - Starting code flow with http://localhost:3000/dashboard?code=bee663b1-49d3-4e39-b94a-7e07457c3295 [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.602 Hub - Dispatching to auth with
Object { event: "codeFlow", data: {}, message: "Retrieving tokens from https://belttgvsdu.auth.us-east-1.amazoncognito.com/oauth2/token" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.602 Hub - Dispatching to auth with
Object { event: "codeFlow", data: {}, message: "Retrieving tokens from https://belttgvsdu.auth.us-east-1.amazoncognito.com/oauth2/token" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.602 AnalyticsClass - on hub capsule auth
Object { event: "codeFlow", data: {}, message: "Retrieving tokens from https://belttgvsdu.auth.us-east-1.amazoncognito.com/oauth2/token" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.602 Hub - Dispatching to auth with
Object { event: "codeFlow", data: {}, message: "Retrieving tokens from https://belttgvsdu.auth.us-east-1.amazoncognito.com/oauth2/token" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.604 Hub - Dispatching to auth with
Object { event: "codeFlow", data: {}, message: "Retrieving tokens from https://belttgvsdu.auth.us-east-1.amazoncognito.com/oauth2/token" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.604 OAuth - Calling token endpoint: https://belttgvsdu.auth.us-east-1.amazoncognito.com/oauth2/token with
Object { grant_type: "authorization_code", code: "bee663b1-49d3-4e39-b94a-7e07457c3295", client_id: "3chm4jkbcn767oqu2m9icconcs", redirect_uri: "http://localhost:3000/dashboard" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.604 Hub - Dispatching to auth with
Object { event: "configured", data: null, message: "The Auth category has been configured successfully" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.605 Hub - Dispatching to auth with
Object { event: "configured", data: null, message: "The Auth category has been configured successfully" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.605 AnalyticsClass - on hub capsule auth
Object { event: "configured", data: null, message: "The Auth category has been configured successfully" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.605 Hub - Dispatching to auth with
Object { event: "configured", data: null, message: "The Auth category has been configured successfully" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.605 Hub - Dispatching to auth with
Object { event: "configured", data: null, message: "The Auth category has been configured successfully" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.606 AnalyticsClass - configure Analytics
Object { Auth: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.606 Parser - parse config
Array(3) [ {…}, "to amplifyconfig", {…} ]
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.606 AWSPinpointProvider - configure Analytics
Object { disabled: undefined, autoSessionRecord: true, Auth: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.606 Hub - Dispatching to analytics with
Object { event: "configured", data: null, message: "The Analytics category has been configured successfully" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.607 AnalyticsClass - on hub capsule analytics
Object { event: "configured", data: null, message: "The Analytics category has been configured successfully" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.607 AnalyticsClass - current configuration
Object { autoSessionRecord: true, Auth: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.607 Storage - storage configure called [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.607 StorageClass - configure Storage [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.607 Parser - parse config
Array(3) [ {…}, "to amplifyconfig", {…} ]
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.608 AWSS3Provider - configure Storage undefined [ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.608 Storage - storage vault configure called [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.608 StorageClass - configure Storage [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.608 Parser - parse config
Array(3) [ {…}, "to amplifyconfig", {…} ]
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.608 AWSS3Provider - configure Storage undefined [ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.609 RestAPI - configure Rest API
Object { opt: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.609 RestAPI - create Rest API instance [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.609 RestClient - API Options
Object { endpoints: [], Auth: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.609 I18n - configure I18n [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.609 I18n - create I18n instance [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.609 PubSub - configure PubSub
Object { opt: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.609 GraphQLAPI - configure GraphQL API
Object { opt: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.609 GraphQLAPI - create Rest instance [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.609 RestClient - API Options
Object { Auth: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.610 RestAPI - configure Rest API
Object { opt: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.610 RestAPI - create Rest API instance [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.610 RestClient - API Options
Object { endpoints: [], Auth: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.610 GraphQLAPI - configure GraphQL API
Object { opt: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.610 GraphQLAPI - create Rest instance [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.610 RestClient - API Options
Object { Auth: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.611 Interactions - configure Interactions
Object { opt: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.611 XR - configure XR
Object { opt: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.611 AbstractXRProvider - configure SumerianProvider
Object { Auth: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.611 Predictions - configure Predictions
Object { Auth: {…} }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.612 Geo - configure Geo [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.612 Parser - parse config
Array(3) [ {…}, "to amplifyconfig", {…} ]
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.613 AmazonLocationServiceProvider - configure Amazon Location Service Provider undefined [ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.624 AuthClass - getting current authenticated user [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.625 AuthClass - getting current authenticated user [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.626 AuthClass - get current authenticated userpool user 2 [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.626 AuthClass - OAuth signIn in progress, waiting for resolution... 2 [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.957 AuthClass - Error in cognito hosted auth response Error: Username and Pool information are required.
CognitoUser CognitoUser.js:73
node_modules bundle.js:11432
node_modules bundle.js:11330
step bundle.js:8399
node_modules bundle.js:8330
fulfilled bundle.js:8284
promise callback*step bundle.js:8299
node_modules bundle.js:8302
node_modules bundle.js:8281
node_modules bundle.js:11243
node_modules bundle.js:8623
__WEBPACK_DEFAULT_EXPORT__ urlListener.ts:19
node_modules bundle.js:8614
node_modules bundle.js:14378
node_modules bundle.js:14377
js App.js:7
factory react refresh:6
Webpack 7
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.957 Hub - Dispatching to auth with
Object { event: "signIn_failure", data: Error, message: "The OAuth response flow failed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.957 Hub - Dispatching to auth with
Object { event: "signIn_failure", data: Error, message: "The OAuth response flow failed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.958 AnalyticsClass - on hub capsule auth
Object { event: "signIn_failure", data: Error, message: "The OAuth response flow failed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.958 Hub - Dispatching to auth with
Object { event: "signIn_failure", data: Error, message: "The OAuth response flow failed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.959 Hub - Dispatching to auth with
Object { event: "signIn_failure", data: Error, message: "The OAuth response flow failed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.959 Hub - Dispatching to auth with
Object { event: "signIn_failure", data: Error, message: "The OAuth response flow failed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.959 Hub - Dispatching to auth with
Object { event: "signIn_failure", data: Error, message: "The OAuth response flow failed" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.959 Hub - Dispatching to auth with
Object { event: "cognitoHostedUI_failure", data: Error, message: "A failure occurred when returning to the Cognito Hosted UI" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.960 Hub - Dispatching to auth with
Object { event: "cognitoHostedUI_failure", data: Error, message: "A failure occurred when returning to the Cognito Hosted UI" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.960 AnalyticsClass - on hub capsule auth
Object { event: "cognitoHostedUI_failure", data: Error, message: "A failure occurred when returning to the Cognito Hosted UI" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.961 Hub - Dispatching to auth with
Object { event: "cognitoHostedUI_failure", data: Error, message: "A failure occurred when returning to the Cognito Hosted UI" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.962 Hub - Dispatching to auth with
Object { event: "cognitoHostedUI_failure", data: Error, message: "A failure occurred when returning to the Cognito Hosted UI" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.962 Hub - Dispatching to auth with
Object { event: "cognitoHostedUI_failure", data: Error, message: "A failure occurred when returning to the Cognito Hosted UI" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.963 AuthClass - OAuth signIn resolved: cognitoHostedUI_failure [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.963 Hub - Dispatching to auth with
Object { event: "cognitoHostedUI_failure", data: Error, message: "A failure occurred when returning to the Cognito Hosted UI" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.964 AuthClass - OAuth signIn resolved: cognitoHostedUI_failure [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.964 Hub - Dispatching to auth with
Object { event: "customState_failure", data: Error, message: "A failure occurred when returning state" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.964 Hub - Dispatching to auth with
Object { event: "customState_failure", data: Error, message: "A failure occurred when returning state" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.964 AnalyticsClass - on hub capsule auth
Object { event: "customState_failure", data: Error, message: "A failure occurred when returning state" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.964 Hub - Dispatching to auth with
Object { event: "customState_failure", data: Error, message: "A failure occurred when returning state" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.965 Hub - Dispatching to auth with
Object { event: "customState_failure", data: Error, message: "A failure occurred when returning state" }
[ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.965 AuthClass - Failed to get user from user pool 2 [ConsoleLogger.ts:115](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
[DEBUG] 46:04.965 AuthClass - The user is not authenticated by the error No current user 2 [ConsoleLogger.ts:125](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts)
error happened The user is not authenticated 2 [Dashboard.js:18](http://localhost:3000/Users/buraktas/aws-cognito-hosted-ui-react/src/components/Dashboard.js)
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
We have the same issue
const credentials = await Auth.federatedSignIn();
console.log('credentials', credentials);
credentials returns undefined.
Any idea what happens with React18 and last version of Amplify?
Same issue here. It appeared when we upgraded react to v18.1.0 Using @aws-amplify/auth: 4.5.4 @aws-amplify/core: 4.5.4
Both packages seem to work fine with react 17.0.2, but updating to 18.1.0 seems to cause the conflict.
Getting undefined credentials and Auth.currentAuthenticatedUser() throws an error because the user appears not to be authenticated.
I found the issue. In my example, I am only requesting 2 custom scopes excluding openid which makes Cognito to creating only an access_token as mentioned in https://aws.amazon.com/blogs/mobile/understanding-amazon-cognito-user-pool-oauth-2-0-grants.
- scope (optional) – A space-separated list of scopes to request for the generated tokens. Note that: An ID token is only generated if the openid scope is requested. The phone, email, and profile scopes can only be requested if openid is also requested. A vended access token can only be used to make user pool API calls if aws.cognito.signin.user.admin is requested.
However, after a redirect completes Amplify requires an idtoken to parse username in _handleAuthResponse method from Auth.ts as shown in https://github.com/aws-amplify/amplify-js/blob/main/packages/auth/src/Auth.ts#L2323-L2325. So, I had to follow a bunch of steps listed below;
- Enable
OpenIDinOpenID Connect scopessection underEdit Hosted UIfrom related Cognito App Client - Update Hosted UI login url from your react application
- Add
openidscope intooauthobject scope list for Amplify configuration - Verify that token endpoint returns both access and id tokens.
Here is the oauth object for my Amplify configuration
oauth: {
domain: 'belttgvsdu.auth.us-east-1.amazoncognito.com',
scope: ['myresourceserver/awesomeapi.read', 'myresourceserver/awesomeapi.write', 'openid'],
redirectSignIn: 'http://localhost:3000/dashboard',
redirectSignOut: 'http://localhost:3000',
responseType: 'code'
}
i found the solution when you are calling Hub.listen('auth',callback) then with call the Auth.CurrentAuthenticatedUser() you will get the user details from Cognito hostedUI the example is below and it should in your root project like app.js
Auth.currentAuthenticatedUser({ bypassCache: true, }) .then((user) => console.log(user)) .catch((err) => console.log(err));
Hub.listen("auth", (data) => { console.log("🚀 ~ file: App.js ~ line 28 ~ Hub.listen ~ data", data); });
Closing this issue as it doesn't seem to be an addressable issue for the library and instead addressed by configuring either the scopes to include 'openid' or utilizing the Hub listener.