Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): add headless auth usage page #3045

Merged
merged 5 commits into from
Nov 22, 2022

Conversation

sreeramsama
Copy link
Contributor

@sreeramsama sreeramsama commented Nov 22, 2022

Description of changes

Add headless auth usage page

Issue #, if available

Description of how you validated changes

Checklist

  • PR description included
  • yarn test passes
  • Tests are updated
  • No side effects or sideEffects field updated
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sreeramsama sreeramsama requested a review from a team as a code owner November 22, 2022 00:34
@changeset-bot
Copy link

changeset-bot bot commented Nov 22, 2022

⚠️ No Changeset found

Latest commit: 9117964

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sreeramsama sreeramsama marked this pull request as draft November 22, 2022 00:42
@sreeramsama sreeramsama marked this pull request as ready for review November 22, 2022 00:53
Comment on lines 29 to 53
### Authentication Check

If you just need to check if you're authenticated or not, you can use the more straightforward `useAuthenticator` hook to access the `authStatus` string. The `authStatus` string can represent the following states:

- `configuring`
- `authenticated`
- `unauthenticated`

> The `configuring` state only occurs when the `Authenticator` is first loading.

```tsx{1,4-7}
import { useAuthenticator } from '@aws-amplify/ui-react-native';

const App = () => {
const { authStatus } = useAuthenticator(context => [context.authStatus]);

// Use the value of authStatus to decide which page to render
return (
<>
{authStatus === 'configuring' && 'Loading...'}
{authStatus !== 'authenticated' ? <Authenticator /> : <Home />}
</>
);
};
```
Copy link
Member

@calebpollman calebpollman Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this. I'm not entirely sure that authStatus works as expected

const Home = () => {
const { user, signOut } = useAuthenticator((context) => [context.user]);

return <button onClick={signOut}>Welcome, {user.username}!</button>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return <button onClick={signOut}>Welcome, {user.username}!</button>;
return <Button onPress={signOut} title={`Welcome, ${user.username}!`} />;

You can use `useAuthenticator` hook to access functions that lets you trigger transitions to the authenticator. Please see [Full API](#full-api) to see all supported transition functions. Any invalid transitions (e.g. `signUp` directly to `authenticated`) will be ignored.

```tsx{1,4-6}
import { useAuthenticator } from '@aws-amplify/ui-react-native';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { useAuthenticator } from '@aws-amplify/ui-react-native';
import { Button } from 'react-native';
import { useAuthenticator } from '@aws-amplify/ui-react-native';

Comment on lines 33 to 34
import { Authenticator } from '@aws-amplify/ui-react-native';
import { View } from 'react-native';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this how all our docs are but generally think it's beet to place React and React Native imports above ours:

Suggested change
import { Authenticator } from '@aws-amplify/ui-react-native';
import { View } from 'react-native';
import { Text, View } from 'react-native';
import { Authenticator } from '@aws-amplify/ui-react-native';

export default function App() {
return (
<Authenticator.Provider>
<View>Your app here</View>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React Native can only render strings within a Text component:

Suggested change
<View>Your app here</View>
<View>
<Text>Your app here</Text>
</View>

@@ -0,0 +1,16 @@
You can use `useAuthenticator` hook to access current signed in `user`. If no user is authenticated, it'll return `undefined`.

```tsx{1,4,8-9}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we need the line highlights?

Comment on lines 9 to 35
export default function App() {
const components = {
SignIn: {
Footer() {
const { toResetPassword } = useAuthenticator();
return (
<View>
<Button onPress={toResetPassword}>
Custom Reset Password
</Button>
</View>
);
},
},
};

return (
<Authenticator components={components}>
{({ signOut, user }) => (
<View>
<Text>Hello {user.username}</Text>
<Button onPress={signOut}>Sign out</Button>
</View>
)}
</Authenticator>
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The components prop does not behave the same between React and React Native:

Suggested change
export default function App() {
const components = {
SignIn: {
Footer() {
const { toResetPassword } = useAuthenticator();
return (
<View>
<Button onPress={toResetPassword}>
Custom Reset Password
</Button>
</View>
);
},
},
};
return (
<Authenticator components={components}>
{({ signOut, user }) => (
<View>
<Text>Hello {user.username}</Text>
<Button onPress={signOut}>Sign out</Button>
</View>
)}
</Authenticator>
);
}
function Footer() {
const { toResetPassword } = useAuthenticator();
return (
<Button onPress={toResetPassword} title="Custom Reset Password" />
);
},
export default function App() {
return (
<Authenticator components={{
SignIn: (props) => <Authenticator.SignIn {...props} Footer={Footer} />
}}>
<View>
<Text>Hello {user.username}</Text>
<Button onPress={signOut} title="Sign out" />
</View>
</Authenticator>
);
}


Then, you can use `useAuthenticator` on your App:

```tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we align all the examples as being jsx

@sreeramsama sreeramsama merged commit 53aa0bd into rna/docs-setup Nov 22, 2022
@sreeramsama sreeramsama deleted the rna/docs-headless-usage branch November 22, 2022 01:49
@0618 0618 mentioned this pull request Nov 22, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants