issue-129 Update signin/up ui-ux #136

Merged
Irev-Dev merged 1 commits from kurt/issue-129-update-signup-in-ui-ux into main 2020-12-05 09:05:24 +01:00
Irev-Dev commented 2020-12-05 08:36:27 +01:00 (Migrated from github.com)

Getting rid of the netlify widgit and rolling our own, gives us the
flexibility to also add the username into the signup process as well
as allow the user to opt into the newsletter at the same time.

Auth is still netlify, via their "gotrue", we're just handling the more
of it.

resolves #129

What's Changed?

There's now our own signIn/Up modal (in web/src/components/LoginModal/LoginModal.js, with help from web/src/components/InputTextForm/InputTextForm.js)

Sign up now has a userName parameter and well a newsletter checkbox
image

error state

image

Sign in has the exact same functionality

image

The forgot password kicks off to separate page (web/src/pages/AccountRecoveryPage/AccountRecoveryPage.js)
image

And once the user has used the recovery link, there's a page for updating their email (web/src/pages/UpdatePasswordPage/UpdatePasswordPage.js)
image

The start hacking now landing page CTA also opens the signin/up modal, but is able to have to open on the signup tab specifically.
image

More explanation comments inline for how conformation token etc were handled. Something I got a little stuck on with redwood changing a data argument to remember, Also worth pointing out that I have not implement email update functionality in the PR, but if you plan to you will probably want to keep this in mind

Getting rid of the netlify widgit and rolling our own, gives us the flexibility to also add the username into the signup process as well as allow the user to opt into the newsletter at the same time. Auth is still netlify, via their "gotrue", we're just handling the more of it. resolves #129 ## What's Changed? There's now our own signIn/Up modal (in `web/src/components/LoginModal/LoginModal.js`, with help from `web/src/components/InputTextForm/InputTextForm.js`) Sign up now has a userName parameter and well a newsletter checkbox ![image](https://user-images.githubusercontent.com/29681384/101236685-5db00100-3727-11eb-93d7-602e5151ae28.png) ### error state ![image](https://user-images.githubusercontent.com/29681384/101236733-a36cc980-3727-11eb-805f-b03f31f0f8c0.png) ### Sign in has the exact same functionality ![image](https://user-images.githubusercontent.com/29681384/101236739-aff12200-3727-11eb-92c6-8cc594cb5cda.png) The `forgot password` kicks off to separate page (`web/src/pages/AccountRecoveryPage/AccountRecoveryPage.js`) ![image](https://user-images.githubusercontent.com/29681384/101236778-e7f86500-3727-11eb-867d-3377cbd91c65.png) And once the user has used the recovery link, there's a page for updating their email (`web/src/pages/UpdatePasswordPage/UpdatePasswordPage.js`) ![image](https://user-images.githubusercontent.com/29681384/101236796-0b231480-3728-11eb-8943-064bb600c035.png) The `start hacking now` landing page CTA also opens the signin/up modal, but is able to have to open on the signup tab specifically. ![image](https://user-images.githubusercontent.com/29681384/101236875-a4522b00-3728-11eb-8adf-ece75478ad37.png) More explanation comments inline for how conformation token etc were handled. Something I got a little stuck on with redwood changing a `data` argument to `remember`, Also worth pointing out that I have not implement email update functionality in the PR, but if you plan to you will probably want to [keep this in mind](https://github.com/netlify/gotrue-js/issues/61)
Yash-R (Migrated from github.com) reviewed 2020-12-05 08:36:27 +01:00
Irev-Dev (Migrated from github.com) reviewed 2020-12-05 08:39:17 +01:00
@@ -0,0 +2,4 @@
import { TextField, FieldError } from '@redwoodjs/forms'
import { useFormContext } from 'react-hook-form'
const InputText = ({ type = 'text', className, name, validation }) => {
Irev-Dev (Migrated from github.com) commented 2020-12-05 08:39:17 +01:00

Very light abstraction of individual text input that still working with react-hoo-forms.
image

Very light abstraction of individual text input that still working `with react-hoo-form`s. ![image](https://user-images.githubusercontent.com/29681384/101236955-1fb3dc80-3729-11eb-856e-456cd5b5a378.png)
Irev-Dev (Migrated from github.com) reviewed 2020-12-05 08:40:33 +01:00
@@ -0,0 +10,4 @@
import { Link, routes } from '@redwoodjs/router'
import { subscribe } from 'src/helpers/subscribe'
const LoginModal = ({ open, onClose, shouldStartWithSignup = false }) => {
Irev-Dev (Migrated from github.com) commented 2020-12-05 08:40:33 +01:00

The login modal
image

The login modal ![image](https://user-images.githubusercontent.com/29681384/101236984-5853b600-3729-11eb-97c2-6ee7a4f73e2e.png)
Irev-Dev (Migrated from github.com) reviewed 2020-12-05 08:50:22 +01:00
@@ -0,0 +31,4 @@
await signUp({
email,
password,
remember: { full_name: name, userName },
Irev-Dev (Migrated from github.com) commented 2020-12-05 08:50:22 +01:00

Any extra data that you want be inside the payload that's passed to the identity-signup netlify function needs to be added to this remember property. It will be in the user_metadata property in the payload.
I'm opting to continue using full_name for the name as this will display nicely as Name in the netlify identity dashboard
image

Why is the data put on a property called remember? I'm not sure but it's pretty confusing since for login, remember is a boolean value that's mean for persisting the users log in state.

Redwood has in mostly places changed gotrue's ordered arguments to named object arguments.
image
d1565a7d05/index.d.ts
Which I'd normally like, but with the name change it becomes confusing figuring how things differ from gotrue's docs, this might be side-effect of integrating with multiple auth providers and trying to unify the API for all of them, which I can't fault. I just got caught on this for a bit.

Any extra data that you want be inside the payload that's passed to the `identity-signup` netlify function needs to be added to this remember property. It will be in the `user_metadata` property in the payload. I'm opting to continue using `full_name` for the name as this will display nicely as `Name` in the netlify identity dashboard ![image](https://user-images.githubusercontent.com/29681384/101237028-c13b2e00-3729-11eb-81df-23e963257ca2.png) Why is the data put on a property called remember? I'm not sure but it's pretty confusing since for `login`, `remember` is a boolean value that's mean for persisting the users log in state. Redwood has in mostly places changed gotrue's ordered arguments to named object arguments. ![image](https://user-images.githubusercontent.com/29681384/101237105-55a59080-372a-11eb-800a-f7bf1a334966.png) https://github.com/netlify/gotrue-js/blob/d1565a7d0576ff613b1c37c46a42d1fcbd720c7c/index.d.ts Which I'd normally like, but with the name change it becomes confusing figuring how things differ from gotrue's docs, this might be side-effect of integrating with multiple auth providers and trying to unify the API for all of them, which I can't fault. I just got caught on this for a bit.
Irev-Dev (Migrated from github.com) reviewed 2020-12-05 08:51:27 +01:00
@@ -0,0 +26,4 @@
try {
setError('')
if (checkBox) {
subscribe({ email, addMessage })
Irev-Dev (Migrated from github.com) commented 2020-12-05 08:51:27 +01:00

Somewhat crude way of subscribing the user to the newsletter, this doesn't got through the API like everything else so it's a little out place. But it works for now.

Somewhat crude way of subscribing the user to the newsletter, this doesn't got through the API like everything else so it's a little out place. But it works for now.
Irev-Dev (Migrated from github.com) reviewed 2020-12-05 08:52:16 +01:00
@@ -0,0 +41,4 @@
const onSubmitSignIn = async ({ email, password }) => {
try {
setError('')
await logIn({ email, password, remember: true })
Irev-Dev (Migrated from github.com) commented 2020-12-05 08:52:16 +01:00

As above mentioned above, remember here has to do with persisting the login.

As above mentioned above, `remember` here has to do with persisting the login.
Irev-Dev (Migrated from github.com) reviewed 2020-12-05 08:57:15 +01:00
Irev-Dev (Migrated from github.com) commented 2020-12-05 08:57:15 +01:00

This effect is big and unruly enough that I probably should have pulled it out into its own custom hook. The use effect has been added to the nav bar since it's on every page, but in reality, I should only ever be needed on the home page since that's where the verification emails redirect to.

Essentially what it's doing is looking for a hash param that's either a confirmation_token or a recovery_token.

If it's a confirmation token it simply sends that off to gotrue, nothing more to do.

If it's a recover token, it sends to token to gotrue and from there re-directs them to the update password page.

This effect is big and unruly enough that I probably should have pulled it out into its own custom hook. The use effect has been added to the nav bar since it's on every page, but in reality, I should only ever be needed on the home page since that's where the verification emails redirect to. Essentially what it's doing is looking for a hash param that's either a confirmation_token or a recovery_token. If it's a confirmation token it simply sends that off to gotrue, nothing more to do. If it's a recover token, it sends to token to gotrue and from there re-directs them to the update password page.
Irev-Dev (Migrated from github.com) reviewed 2020-12-05 08:58:56 +01:00
@@ -0,0 +12,4 @@
const { client } = useAuth()
const onSubmit = ({ email }) => {
client
.requestPasswordRecovery(email)
Irev-Dev (Migrated from github.com) commented 2020-12-05 08:58:55 +01:00

Send recovery email.

Send recovery email.
Irev-Dev (Migrated from github.com) reviewed 2020-12-05 09:00:56 +01:00
@@ -0,0 +19,4 @@
}
client
.currentUser()
.update({ password })
Irev-Dev (Migrated from github.com) commented 2020-12-05 09:00:56 +01:00

This update function can be used to update any property on the user. Though, for email (I haven't built email update UI), but if you plan to it's worth knowing there is an undocumented token needed

This update function can be used to update any property on the user. Though, for email (I haven't built email update UI), but if you plan to it's worth knowing there is an [undocumented token needed](https://github.com/netlify/gotrue-js/issues/61)
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: h3n3/cadhub#136