12

I am using react-native and the out of the box aws-amplify-react-native to sigin, signup users. Users are able to authenticate successfully but getting the following error in the signin form "no current user"

I pumped up the log level to debug in the application. I can see the user successfully authenticate and I get back the JWT token but I see the following in the logs:

[DEBUG] 22:47.149 AuthClass - Failed to get user from user pool
[ERROR] 22:47.154 AuthClass - Failed to get the signed in user No current user
[DEBUG] 22:47.161 AuthPiece - No current user

Below is a snippet of my code:

import { ConfirmSignIn, ConfirmSignUp, ForgotPassword, RequireNewPassword, SignIn, SignUp, VerifyContact, withAuthenticator } from 'aws-amplify-react-native';

const RootStack = createStackNavigator(
  {
    Login: LoginScreen,
    Main: MainScreen,
    Customer: CustomerScreen,
    Reports: ReportsScreen,
    Signup: SignupScreen
  },
  {
    initialRouteName: 'Main',
  }
);

const AppContainer = createAppContainer(RootStack);

export class App extends React.Component {
  render() {
    return (
      <AppContainer />
    );
  }
}

export default withAuthenticator(App);

When I run my app. I see the default Sign In form for Amplify, I use it to enter username and password and then click on "SIGN IN" button which does successfully authenticate but I get the "No current user error" as shown above.

F. K.
  • 694
  • 3
  • 9
  • 23

5 Answers5

15

I had the similar problem. I removed the cookie storage block from the configure method and it worked.

Sukesh Nemane
  • 151
  • 1
  • 4
  • I also removed existing cookies, the above solution worked – Chris Jun 09 '20 at 00:14
  • The solution worked for me too. So does that mean we shouldn't use cookie storage for react native apps ?? Or is like an issue only in the dev environment or should we include it back for release ?? – Midhun Kumar Oct 10 '20 at 07:51
  • That solved my problem! Thank you! – Konrad G Nov 18 '21 at 19:22
  • care to share a code example? – zero_cool Mar 08 '23 at 20:01
  • Removing cookieStorage property works fine, but the problem is the domain property inside them. It's important keep the Amplify data saved in cookies, so before removing, make sure that your domain value is correct. Thanks for your solution. – Jose Alvarez Jun 08 '23 at 12:53
5

Are you using the cookieStore? If true, do you use the secure flag? If so, change its value to false in the development environment.

2

The error is literally saying No current user - you need to sign in using the supported identity provider.

My solution to that:

import { Amplify } from "@aws-amplify/core";
import { Auth } from "@aws-amplify/auth";
import { CookieStorage } from 'amazon-cognito-identity-js';
import amplifyConfig from "../lib/Amplify";

Amplify.configure(amplifyConfig);

const cookieStorage = new CookieStorage(amplifyConfig.Auth.cookieStorage);
// cookie that is set before Cognito redirect to prevent infinite loop if authorization fails due to other reason than "No current user"
const redirectedFromAuthorize = cookieStorage.getItem("redirected-from-authorize");

...

Auth.currentAuthenticatedUser()
  .then(user => {
    setUser(user); // your custom function to do something with user attributes
    // authorization was successfull, we can remove the redirect cookie
    cookieStorage.removeItem("redirected-from-authorize");
  })
  .catch(err => {
    console.error(err);

    // if the cookie is set, it means the authorization failed again and you should not redirect back to Cognito
    if (!redirectedFromAuthorize) {
      // set redirect cookie, so that we know next time the error is reocurring
      cookieStorage.setItem("redirected-from-authorize", 'true');
      // redirect to Cognito hosted UI
      return Auth.federatedSignIn();
    }
  });
ANTARA
  • 810
  • 1
  • 13
  • 20
  • 2
    You should not manage cookies directly in JavaScript. If your app is compromise with an XSS, the attacker will be able to download the user cookie – Netsab612 Apr 08 '22 at 12:51
1

I had this issue and I was able to sort it out by making the password of the user permanent with the command:

aws cognito-idp admin-set-user-password --user-pool-id us-east-1_XXX --username XXXXX --password XXXX  --permanent
CodeChanger
  • 7,953
  • 5
  • 49
  • 80
0

resolved

Togle "secure" to true in config:

Auth: { region: "us-west-2", userPoolId: "us-west-2_xxxxx", userPoolWebClientId: "xxxxxx", cookieStorage: { domain: "localhost", path: "/", expires: 5, secure: true, // <------------------------ true },

XnoX
  • 1