Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import Amplify, { Auth } from 'aws-amplify';
- const Amplify = require('aws-amplify');
- // const Amplify = require('Amplify');
- // import awsmobile from './../../aws-exports';
- const awsmobile = require('./../../aws-exports');
- window.Amplify = Amplify;
- console.log(Amplify, awsmobile);
- window.userPoolInfo = Amplify.configure(awsmobile);
- // import { Auth } from 'aws-amplify';
- let AmplifyLogin = {
- username: '',
- login: function(inputUserName, password)
- {
- console.log('login called');
- // For advanced usage
- // You can pass an object which has the username, password and validationData which is sent to a PreAuthentication Lambda trigger
- Amplify.Auth.signIn({
- username: inputUserName, // Required, the username
- password: password, // Optional, the password
- //validationData, // Optional, a random key-value pair map which can contain any key and will be passed to your PreAuthentication Lambda trigger as-is. It can be used to implement additional validations around authentication
- }).then(user => console.log(user))
- .catch(err => console.log('LOGIN FAILED',err));
- },
- signup: function(newUsername, password)
- {
- this.username = newUsername;
- Amplify.Auth.signUp({
- username: newUsername,
- password,
- attributes: {
- // email, // optional
- // phone_number, // optional - E.164 number convention
- // other custom attributes
- },
- validationData: [] //optional
- })
- .then(data => console.log(data))
- .catch(err => console.log(err));
- },
- setConfirmationCode(code){
- // After retrieving the confirmation code from the user
- Amplify.Auth.confirmSignUp(this.username, code, {
- // Optional. Force user confirmation irrespective of existing alias. By default set to True.
- forceAliasCreation: true
- }).then(data => console.log(data))
- .catch(err => console.log(err));
- },
- resendSignUp(){
- Amplify.Auth.resendSignUp(this.username).then(() => {
- console.log('code resent successfully');
- }).catch(e => {
- console.log(e);
- });
- }
- };
- module.exports = AmplifyLogin;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement