From 400aebd343e58b8d83774de207eaa9dff1d9ee87 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Tue, 30 Jun 2020 17:12:10 -0500 Subject: [PATCH] Add Sign Up User With Email And Password as Amplify til --- README.md | 7 +++- .../sign-up-user-with-email-and-password.md | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 amplify/sign-up-user-with-email-and-password.md diff --git a/README.md b/README.md index a611832..a0c5a1a 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,14 @@ and pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_929 TILs and counting..._ +_930 TILs and counting..._ --- ### Categories * [Ack](#ack) +* [Amplify](#amplify) * [Chrome](#chrome) * [Clojure](#clojure) * [CSS](#css) @@ -54,6 +55,10 @@ _929 TILs and counting..._ - [Case-Insensitive Search](ack/case-insensitive-search.md) - [List Available File Types](ack/list-available-file-types.md) +### Amplify + +- [Sign Up User With Email And Password](amplify/sign-up-user-with-email-and-password.md) + ### Chrome - [Access A Value Logged To The Console](chrome/access-a-value-logged-to-the-console.md) diff --git a/amplify/sign-up-user-with-email-and-password.md b/amplify/sign-up-user-with-email-and-password.md new file mode 100644 index 0000000..705d200 --- /dev/null +++ b/amplify/sign-up-user-with-email-and-password.md @@ -0,0 +1,32 @@ +# Sign Up User With Email And Password + +[AWS Amplify](https://aws.amazon.com/amplify/) +[Auth](https://docs.amplify.aws/lib/auth/getting-started/q/platform/js) offers +both federated and username/password based authentication. Though the docs +aren't clear, the required `username` parameter can be used as the email field +with the [`signUp` +API](https://aws-amplify.github.io/amplify-js/api/classes/authclass.html#signup). + +```javascript +import { Auth } from 'aws-amplify'; + +async function signUp({ email, password }) { + try { + const user = await Auth.signUp({ + username: email, + password, + attributes: {}, + }); + console.log({ user }); + } catch (error) { + console.log('error signing up:', error); + } +} +``` + +Once the user has entered an email and password into the Sign Up form, those +values can be passed to this `signUp` function. The `email` value is passed as +the `username` and the `password` goes in as is. + +Amplify Auth will interpret the `username` as an email and register it as the +contact email for this user.