Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. // import Amplify, { Auth } from 'aws-amplify';
  2. const Amplify = require('aws-amplify');
  3. // const Amplify = require('Amplify');
  4.  
  5. // import awsmobile from './../../aws-exports';
  6. const awsmobile = require('./../../aws-exports');
  7. window.Amplify = Amplify;
  8. console.log(Amplify, awsmobile);
  9. window.userPoolInfo = Amplify.configure(awsmobile);
  10. // import { Auth } from 'aws-amplify';
  11.  
  12. let AmplifyLogin = {
  13. username: '',
  14. login: function(inputUserName, password)
  15. {
  16. console.log('login called');
  17.  
  18. // For advanced usage
  19. // You can pass an object which has the username, password and validationData which is sent to a PreAuthentication Lambda trigger
  20. Amplify.Auth.signIn({
  21. username: inputUserName, // Required, the username
  22. password: password, // Optional, the password
  23. //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
  24. }).then(user => console.log(user))
  25. .catch(err => console.log('LOGIN FAILED',err));
  26. },
  27. signup: function(newUsername, password)
  28. {
  29. this.username = newUsername;
  30. Amplify.Auth.signUp({
  31. username: newUsername,
  32. password,
  33. attributes: {
  34. // email, // optional
  35. // phone_number, // optional - E.164 number convention
  36. // other custom attributes
  37. },
  38. validationData: [] //optional
  39. })
  40. .then(data => console.log(data))
  41. .catch(err => console.log(err));
  42.  
  43.  
  44.  
  45. },
  46. setConfirmationCode(code){
  47. // After retrieving the confirmation code from the user
  48. Amplify.Auth.confirmSignUp(this.username, code, {
  49. // Optional. Force user confirmation irrespective of existing alias. By default set to True.
  50. forceAliasCreation: true
  51. }).then(data => console.log(data))
  52. .catch(err => console.log(err));
  53. },
  54. resendSignUp(){
  55.  
  56. Amplify.Auth.resendSignUp(this.username).then(() => {
  57. console.log('code resent successfully');
  58. }).catch(e => {
  59. console.log(e);
  60. });
  61. }
  62. };
  63.  
  64. module.exports = AmplifyLogin;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement