Home Manual Reference Source Test Repository

Function

Static Public Summary
public

authenticate(username: string, password: string, userPool: object): Promise<object>

Authenticates with a user pool, and handles responses.

public

buildLogins(username: string, jwtToken: string, config: object): *

builds the federated identity pool login structure

public

changePassword(user: object, oldPassword: string, newPassword: string)

Change a user's password

public

cognito(state: object, action: object): *

reducer function to be passed to redux combineReducers

public

createGuard(store: object, forbiddenUrl: string): function

creates a guard function you can use in <Route> tags

public

direct(state: object, dispatch: function)

transitions directly from AUTHENTICATED to LOGGING_IN

public

sends the email verification code and transitions to the correct state

public

requires email verification before transitioning from AUTHENTICATED

public

enable(store: object, f: function)

subscribes a "policy" function to the store, and calls it with the state and the dispatch function

public

fetchAttributes(state: object, dispatch: function)

fetches and stores attributes before transitioning from AUTHENTICATED

public

Fetches the user attributes from Cognito, and turns them into an object

public

identityPoolLogin(state: object, dispatch: function)

logs into the single federated identity pool to transition from LOGGING_IN to LOGGED_IN

public

mkAttrList(attributes: object): array

convert an attribute dictionary to an attribute list

public

establishes a session with the user pool, and logs into the federated identity pool using a token from the session

public

registerUser(userPool: object, config: object, username: string, password: string, attributes: object): Promise<object>

sign up this user with the user pool provided

public

Request that a verification code is sent by email or SMS to verify an attribute

public

setupCognito(store: *, config: *)

sets up react-cognito with default policies.

public

updateAttributes(user: object, attributes: object): Promise<object>

update the attributes in Cognito

Static Public

public authenticate(username: string, password: string, userPool: object): Promise<object> source

import {authenticate} from 'react-cognito/src/auth.js'

Authenticates with a user pool, and handles responses. if the authentication is successful it then logs in to the identity pool.

returns an action depending on the outcome. Possible actions returned are:

  • login - valid user who is logged in
  • loginFailure - failed to authenticate with user pool or identity pool
  • mfaRequired - user now needs to enter MFA
  • newPasswordRequired - user must change password on first login
  • emailVerificationRequired - user must verify their email address
  • emailVerificationFailed - email verification is required, but won't work

Dispatch the resulting action, e.g.:

const { userPool, config } = state.cognito;
authenticate(username, password, userPool, config).then(dispatch);

Params:

NameTypeAttributeDescription
username string

the username provided by the user

password string

the password provided by the user

userPool object

a Cognito User Pool object

Return:

Promise<object>

a promise that resolves an action to be dispatched

public buildLogins(username: string, jwtToken: string, config: object): * source

import {buildLogins} from 'react-cognito/src/utils.js'

builds the federated identity pool login structure

Params:

NameTypeAttributeDescription
username string

the username of the user

jwtToken string

a JWT Token from the session

config object

the cognito react config object

Return:

*

public changePassword(user: object, oldPassword: string, newPassword: string) source

import {changePassword} from 'react-cognito/src/utils.js'

Change a user's password

Params:

NameTypeAttributeDescription
user object

the cognito user object

oldPassword string

the current password

newPassword string

the new password

public cognito(state: object, action: object): * source

import {cognito} from 'react-cognito/src/reducers.js'

reducer function to be passed to redux combineReducers

Params:

NameTypeAttributeDescription
state object
action object

Return:

*

public createGuard(store: object, forbiddenUrl: string): function source

import {createGuard} from 'react-cognito/src/guard.js'

creates a guard function you can use in <Route> tags

Params:

NameTypeAttributeDescription
store object

the redux store

forbiddenUrl string

the default url to navigate to if forbidden

Return:

function

a function that can be provided to onEnter

public direct(state: object, dispatch: function) source

import {direct} from 'react-cognito/src/policy.js'

transitions directly from AUTHENTICATED to LOGGING_IN

Params:

NameTypeAttributeDescription
state object

the redux store state

dispatch function

the dispatch function

public emailVerificationFlow(user: object, attributes: object): Promise<object> source

import {emailVerificationFlow} from 'react-cognito/src/auth.js'

sends the email verification code and transitions to the correct state

Params:

NameTypeAttributeDescription
user object

the CognitoUser object

attributes object

the attributes dictionary

Return:

Promise<object>

a promise that resolves to a redux action

public emailVerificationRequired(state: object, dispatch: function) source

import {emailVerificationRequired} from 'react-cognito/src/policy.js'

requires email verification before transitioning from AUTHENTICATED

Params:

NameTypeAttributeDescription
state object

the redux store state

dispatch function

the dispatch function

public enable(store: object, f: function) source

import {enable} from 'react-cognito/src/policy.js'

subscribes a "policy" function to the store, and calls it with the state and the dispatch function

Params:

NameTypeAttributeDescription
store object

the redux store

f function

f(state, dispatch)

public fetchAttributes(state: object, dispatch: function) source

import {fetchAttributes} from 'react-cognito/src/policy.js'

fetches and stores attributes before transitioning from AUTHENTICATED

Params:

NameTypeAttributeDescription
state object

the redux store state

dispatch function

the dispatch function

public getUserAttributes(user: object): Promise source

import {getUserAttributes} from 'react-cognito/src/attributes.js'

Fetches the user attributes from Cognito, and turns them into an object

Params:

NameTypeAttributeDescription
user object

the cognito user object

Return:

Promise

resolves with the attributes or rejects with an error message

public identityPoolLogin(state: object, dispatch: function) source

import {identityPoolLogin} from 'react-cognito/src/policy.js'

logs into the single federated identity pool to transition from LOGGING_IN to LOGGED_IN

Params:

NameTypeAttributeDescription
state object

the redux store state

dispatch function

the dispatch function

public mkAttrList(attributes: object): array source

import {mkAttrList} from 'react-cognito/src/attributes.js'

convert an attribute dictionary to an attribute list

Params:

NameTypeAttributeDescription
attributes object

a dictionary of attributes

Return:

array

AWS expected attribute list

public performLogin(user: object, config: object): Promise<object> source

import {performLogin} from 'react-cognito/src/auth.js'

establishes a session with the user pool, and logs into the federated identity pool using a token from the session

Params:

NameTypeAttributeDescription
user object

the CognitoUser object

config object

the react-cognito config

Return:

Promise<object>

an action to be dispatched

public registerUser(userPool: object, config: object, username: string, password: string, attributes: object): Promise<object> source

import {registerUser} from 'react-cognito/src/auth.js'

sign up this user with the user pool provided

Params:

NameTypeAttributeDescription
userPool object

a Cognito userpool (e.g. state.cognito.userPool)

config object

the react-cognito config object

username string

the username

password string

the password

attributes object

an attributes dictionary

Return:

Promise<object>

a promise that resolves a redux action

public sendAttributeVerificationCode(user: object, attribute: string) source

import {sendAttributeVerificationCode} from 'react-cognito/src/attributes.js'

Request that a verification code is sent by email or SMS to verify an attribute

Params:

NameTypeAttributeDescription
user object

the cognito user object

attribute string

the attribute name

Test:

public setupCognito(store: *, config: *) source

import {setupCognito} from 'react-cognito/src/policy.js'

sets up react-cognito with default policies.

Params:

NameTypeAttributeDescription
store *
config *

public updateAttributes(user: object, attributes: object): Promise<object> source

import {updateAttributes} from 'react-cognito/src/attributes.js'

update the attributes in Cognito

Params:

NameTypeAttributeDescription
user object

the CognitoUser object

attributes object

an attributes dictionary with the attributes to be updated

Return:

Promise<object>

a promise that resolves to a redux action