Ember Cognito Integration

4.0.2 · active · verified Wed Apr 22

ember-cognito is an Ember Addon that integrates the Ember.js authentication library, ember-simple-auth, with AWS Amplify and AWS Cognito User Pools. It provides a custom authenticator and a service to access Amplify authentication methods, streamlining user authentication in Ember applications using AWS's managed identity service. The current stable version is 4.0.2, released in December 2025. This addon has a consistent release cadence, frequently updating to support newer Ember.js and AWS Amplify versions. A key differentiator is its seamless integration with ember-simple-auth, abstracting the complexities of interacting directly with the AWS Cognito SDK via Amplify, and providing helpers for common authentication flows like sign-up, confirmation, and session management. It also requires specific configuration for modern Ember v2 addons and Embroider compatibility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate a user with AWS Cognito using the `ember-simple-auth` session service and the `authenticator:cognito` authenticator. It also includes an example of using the injected `cognito` service for user registration.

import Component from '@ember/component';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';

// Ensure your config/environment.js has:
// cognito: {
//   poolId: "<your Cognito User Pool ID>",
//   clientId: "<your Cognito App Client ID>",
// },

export default class LoginComponent extends Component {
  @service session;
  @tracked username = '';
  @tracked password = '';
  @tracked errorMessage = '';

  @action
  updateUsername(event) {
    this.username = event.target.value;
  }

  @action
  updatePassword(event) {
    this.password = event.target.value;
  }

  @action
  async authenticate() {
    this.errorMessage = ''; // Clear previous errors
    try {
      await this.session.authenticate('authenticator:cognito', {
        username: this.username,
        password: this.password
      });
      // Authentication successful, redirect or update UI
      console.log('User authenticated successfully!');
    } catch (error) {
      this.errorMessage = error.message || String(error);
      console.error('Authentication error:', this.errorMessage);
    }
  }

  // Example of using the cognito service for signup
  @service cognito;
  @tracked signUpUsername = '';
  @tracked signUpPassword = '';
  @tracked signUpEmail = '';
  @tracked signUpSuccess = false;

  @action
  async signUp() {
    this.errorMessage = '';
    try {
      await this.cognito.signUp(
        this.signUpUsername,
        this.signUpPassword,
        { email: this.signUpEmail }
      );
      this.signUpSuccess = true;
      console.log('Sign-up successful, check email for confirmation code.');
    } catch (error) {
      this.errorMessage = error.message || String(error);
      console.error('Sign-up error:', this.errorMessage);
    }
  }
}

view raw JSON →