DEV Community

Cover image for How to Easily Customize The AWS Amplify Authentication UI

How to Easily Customize The AWS Amplify Authentication UI

Kyle Galbraith on November 29, 2018

For parler.io I have been experimenting with adding authentication to the project. This would allow conversions to be tied to users and enable a sl...
Collapse
 
georgebelanger profile image
George Belanger • Edited

Hey everyone, due to a recent change to the Amplify signIn function, you now have to pass the event into your super.signIn function on line 61-ish:

in customSignIn.js around line 61
onClick={() => super.signIn()} ---> onClick={(event) => super.signIn(event)}

or you will get this error: Uncaught (in promise) TypeError: Cannot read property 'preventDefault' of undefined .

Here is the changes they made: github.com/aws-amplify/amplify-js/...

Here is the article I used to figure out what was wrong: stackoverflow.com/questions/475077...

Collapse
 
jukkahuuskonen profile image
Jukka Huuskonen

Hi Kyle,

Was there some reason to not use the withAuthenticator()? As far as I understood from reading the docs, you can pass customized components to withAuthenticator too.

Here is a link to the part of docs I'm talking about:
aws-amplify.github.io/docs/js/auth...

If I understood the docs correctly, you could have just passed the CustomSignIn-component to the withAuthenticator.

Collapse
 
kylegalbraith profile image
Kyle Galbraith • Edited

Great question! I didn't use withAuthenticator because I always wanted to use hide=[] to hide a lot of the default Amplify screens that I didn't need.

Collapse
 
jukkahuuskonen profile image
Jukka Huuskonen • Edited

Kyle wrote:

'because I always wanted to use hide=[] to hide a lot of the default Amplify screens that I didn't need.'

Isn't that what the TRUE/FALSE tag in withAuthenticator is used for?

Set it to TRUE (hide=[NONE]) and all AWS-components are shown.

Set it to FALSE (hide=[ALL]) like this and add your custom component(s) into an array:

export default withAuthenticator(App, false, [<YOURCUSTOMSIGNIN />]);

And only component is shown (and all the other custom components in the list). Of course you can also add standard AWS-components to the list there.

Thread Thread
 
kylegalbraith profile image
Kyle Galbraith

No the true/false for the HOC is for showing greetings. You could probably get this setup to work with the HOC but I preferred to go this route in the event I have further customization I need to make.

Thread Thread
 
jukkahuuskonen profile image
Jukka Huuskonen

Ahh, thanks. Couldn't find that in docs, so jumped to a coclusions, since it seemed to work that way (I just wanted the Greeting away and thought it did it to other components too...)

Collapse
 
jukkahuuskonen profile image
Jukka Huuskonen

Ok, have to look into that myself a bit more. Great article and helped me a lot :)

Collapse
 
david_j_eddy profile image
David J Eddy

Nice article Kyle! Easy to follow and explains the steps but not overly verbose, nice pacing.

I saw a AWS team demo this a Neilson a couple months back during a MeetUp. Makes me want to get into mobile dev. :)

Collapse
 
kylegalbraith profile image
Kyle Galbraith

Thank you for the kind comments David! It is a very slick framework and it is continuously being improved, definitely worth checking out.

Collapse
 
kayis profile image
K

Inheritance? In my React?! xD

Collapse
 
kylegalbraith profile image
Kyle Galbraith

React is certainly not my strongest area of expertise. Certainly, composition would be better here, but getting this customized to fit my needs was a jaunt in itself. Maybe I can circle back to this in the future.

Collapse
 
kayis profile image
K

Yes, the clean way would probably be to use the auth function calls directly, but I guess this is also more work.

Collapse
 
firelordozai01 profile image
Alejandro Ozai • Edited

I'm new to amplify and react as well. Is there an article that guides you in building a custom login page using amplify and modern react with functional components and hooks?

Collapse
 
ivashka007 profile image
Ivan Krasulya

Good article, but I do not quite understand how App and AppWithAuth are interrelated. What component do we include in index.js? And how do we generally connect AppWithAuth?

Collapse
 
kylegalbraith profile image
Kyle Galbraith

At the highest level, you would include AppWithAuth as the entry point for your app. This allows you to wrap your entire application with an authentication layer as demoed here.

Collapse
 
seth1993 profile image
Seth Bailey

It would be cool to add an article with examples for react-native. The library aws-amplify-react-native is slightly different and I'm having difficulty with changeState for forgotPassword and signUp

Collapse
 
petergreekbase profile image
peter-greekbase • Edited

Any idea of how to circumvent:
TS2339: Property 'authState' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'.

in App, at:
if (this.props.authState === 'signedIn')

?