GithubHelp home page GithubHelp logo

daikiojm / angular-aws-amplify Goto Github PK

View Code? Open in Web Editor NEW
47.0 47.0 34.0 93 KB

Sample implementation for AWS Amplify in Angular project

TypeScript 79.44% JavaScript 8.15% CSS 2.28% HTML 10.13%
angular aws aws-sdk

angular-aws-amplify's Introduction

angular-aws-amplify's People

Contributors

daikiojm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

angular-aws-amplify's Issues

Auth workflow

First of all, I would like to thank you for this great simple code, I am wondering about the authorization workflow, when the user sign up and confirm his account, he must be redirected to the login page and login into his account which I think is an unnecessary step, how can I make the user get signed in after the confirmation without having to type the user name and password and be redirected to the login page?

Does Not Account for Auth Challenges

There is an issue where if Cognito presents the user with an authorization challenge, such as "NEW_PASSWORD_REQUIRED", the user will not be fully authenticated but the application incorrectly believes a user is logged in until it is reloaded/refreshed.

Problem starts here (auth.service.ts line 34):

public signIn(email, password): Observable<any> {
      return fromPromise(Auth.signIn(email, password))
      .pipe(
        tap(() => this.loggedIn.next(true))
      );
  }

If there is a challenge like "NEW_PASSWORD_REQUIRED", loggedIn is still set to true even though the authentication process has not completed.

Then, here (login.component.ts line 31):

onSubmitLogin(value: any) {
    const email = value.email, password = value.password;
    this.auth.signIn(email, password)
      .subscribe(
        result => {
          this.router.navigate(['/']);
        },
        error => {
          console.log(error);
        });
  }

When onSubmitLogin gets the result from the auth service signIn function, there is no error, so the login component also continues on as though the user authentication was successful.

This is particularly critical when building a site with Cognito user pools where there is no open registration and/or admins create users manually. All new Cognito users created manually will encounter a NEW_PASSWORD_REQUIRED challenge upon attempting to authenticate.

Here is a suggestion...

My auth service signIn function:

public signIn(email, password): Observable<any> {
    return fromPromise(Auth.signIn(email, password)).pipe(
      tap((result) => {
        if(result.constructor.name === "CognitoUser") {
          this.loggedIn.next(true);
        }
        else {
          //Rise to the challenge
        }
      }, (error) => {
        //Handle any errors.
      })
    );
  }

And my login component onSubmit:

onSubmitLogin(value: any) {
    const email = value.email, password = value.password;
    this.auth.signIn(email, password)
      .subscribe(
        result => {
          if(result.constructor.name === "CognitoUser") {
            this.messenger.add("Congrats! You've been authenticated", "success");
          }
          else {
            //Rise to the challenge
          }
        },
        error => {
          console.log(error);
        });
  }

When a result is received without error, it now checks to ensure there is a CognitoUser returned. If not, then code can be implemented to deal with challenge scenarios.

Unit tests

Hi.
I would appreciate it if you also create unit tests for services, components and modules so that I can use it as a baseline.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.