amplify-js: Angular - signedIn user is not persisted

Do you want to request a feature or report a bug? Once the user sign’s in the authenticated details are not persisted. .

Auth.signIn(this.loginForm.value.username, this.loginForm.value.password)
     .then((user) => console.log('signed-in user',user));

Now refresh your window and user is not persisted

    Auth.currentAuthenticatedUser()
      .then(user=>console.log('currentUser ::',user))
      .catch(err=>console.log('error curretUser::',err));


The documentation indicates that the persistence is managed by Amplify in React, but does that also hold true for Angular or we will need to manage it ourselves

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 15 (5 by maintainers)

Most upvoted comments

My bad. I was configuring Auth through the AmplifyService like so:

// ...
constructor(private _amplify: AmplifyService) {
  this._amplify.auth().configure(...)
}

The AmplifyService has a decorator that automatically tries to get the current authenticated user from Local Storage. Previously I must have had some asynchronous luck, so that the configuration was done before The service attempted to get the user.

My advice is, make sure you configureAuth directly and not via AmplifyService and do it as early as possible in your application’s bootstrap process. I moved it to the app.module.ts file.