question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Native - withAuthenticator - Custom Greetings UI

See original GitHub issue

** Which Category is your question related to? **

  • Authentication

** What AWS Services are you utilizing? **

  • Cognito, AppSync

Hi There! Is it possible to replace the built in Greetings component in aws-amplify-react-native with a custom component when using withAuthenticator?

From looking at the related code for withAuthenticator here it appears that the Amplify’s built-in Greetings component is hard-coded.

We’ve followed the documentation for custom UI here and have successfully built our own components for SignIn, etc. Unfortunately we have been unable override Greetings.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jordanranzcommented, Jan 4, 2019

Glad you got this working!

I think your solution is the preferred way to achieve what you are asking for. Since the Greetings component simply provides a UI wrapper for sign out and username text, it is simpler to use the Auth method mentioned above and create your own Header above your app. I will close this for now. Please reopen if you experience any related issue.

1reaction
jessedoylecommented, Jan 4, 2019

Hi @jordanranz! Thanks for reminding me of this issue!

We ended up going down an alternate path to achieve the same results (I’ll explain this later), but I can give a brief overview of the issue we encountered.

Unfortunately I don’t have the exact code we had written handy, but it was similar to this:

// App.js
import React from 'react';
import { StyleSheet } from 'react-native';
import { withAuthenticator } from 'aws-amplify-react-native';
import { 
  Greetings,
  Loading,
  SignIn,
  ForgotPassword
} from './customAuth';

const authComponents = [
  <Greetings />
  <Loading />,
  <SignIn />,
  <ForgotPassword />,
]

const App = ...

export default withAuthenticator(
  App,
  false,
  authComponents,
  null,
  StyleSheet.create({
    container: {
      flex: 1,
    },
  }),
);

// customAuth/Greetings.js
import React from 'react';
import { 
  Text,
  View
} from 'react-native';
import { Auth } from 'aws-amplify';
import { Greetings } from 'aws-amplify-react-native';

export default class CustomGreetings extends Greetings {
  render() {
    const name = Auth.user && Auth.user.username;
    const message = `Hello, ${name}`;

    return (
      <View>
        <Text>{message}</Text>
      </View>
    );
  }
}

Unfortunately this approach didn’t work for us and the custom Greetings component didn’t appear to display in the Authenticator component.

I wasn’t able to troubleshoot the root issue, but I believe the custom Greetings component was not displayed due to the following:

  • The Greetings component defines a render function as opposed to a showComponent function.
  • The Greetings class does not set the _validAuthStates property in the constructor (example).

The approach we ultimately went forward with was creating our own custom component to display the user message by reading from Auth.currentAuthenticatedUser() directly. Our custom component was able to initiate a sign out by utilizing the onStateChange prop that is passed down from withAuthenticator.

I would say we were able to work around the issue we were encountering, so feel free to close this issue if necessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authenticator - React Native - AWS Amplify Docs
The withAuthenticator HOC wraps an Authenticator component. Using Authenticator directly gives you more customization options for your UI.
Read more >
How to customise the UI after a user is signed in using ...
ok finally finally figured this out... use hideDefault={true} in , then add all the other components except for Greetings (includes signout ...
Read more >
Amplify UI's new Authenticator component makes it easy to ...
In this blog post we will deploy a React app with Amplify Hosting, set up auth, and then integrate the <Authenticator> UI component...
Read more >
AWS Amplify Authentication in React Native (Full tutorial)
Learn how to integrate a custom authentication UI in React Native with AWS Amplify Authentication. The tutorial will walk you through the ...
Read more >
A Complete Guide to the Amplify React Authentication ...
A Complete Guide to the Amplify React Authentication Components. A few weeks ago, the team I ... import { withAuthenticator } from '@aws-amplify/ui-react'....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found