import { useRef } from 'react';
import classNames from 'classnames';
import {
Flex,
Heading,
Text,
Link,
View,
Authenticator,
useBreakpointValue,
} from '@aws-amplify/ui-react';
import { HomeCode } from '@/components/home/HomeCode';
import { HomeCTA } from '@/components/home/HomeCTA';
import { CodeHighlight } from '@/components/CodeHighlight';
import { useIntersectionObserver } from '@/components/useIntersection';
import { FlutterAuthenticatorExample } from '@/components/FlutterAuthenticatorExample';
import { BrowserMock } from '@/components/home/BrowserMock';
import { trackScroll } from '@/utils/track';
import { ExpoSnack, ExpoSnackWithExports } from '@/components/ExpoSnack';
// TODO: grab this code from actual examples so we don't need to keep these in sync
const authenticatorCode = {
angular: `
Welcome {{ user.username }}!
`,
react: `import { Amplify } from 'aws-amplify';
import { Authenticator } from '@aws-amplify/ui-react';
import '@aws-amplify/ui-react/styles.css';
import awsExports from './aws-exports';
Amplify.configure(awsExports);
export default function App() {
return (
{({ signOut, user }) => (
Hello {user.username}
)}
);
}`,
vue: `
Hello {{ user.username }}!
`,
flutter: `class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State createState() => _MyAppState();
}
class _MyAppState extends State {
@override
void initState() {
super.initState();
_configureAmplify();
}
void _configureAmplify() async {
try {
await Amplify.addPlugin(AmplifyAuthCognito());
await Amplify.configure(amplifyconfig);
safePrint('Successfully configured');
} on Exception catch (e) {
safePrint('Error configuring Amplify: $e');
}
}
@override
Widget build(BuildContext context) {
return Authenticator(
child: MaterialApp(
builder: Authenticator.builder(),
home: const Scaffold(
body: Center(
child: Text('You are logged in!'),
),
),
),
);
}
}`,
'react-native': `import React from 'react';
import { Button } from 'react-native';
import { Amplify } from 'aws-amplify';
import { Authenticator, useAuthenticator } from '@aws-amplify/ui-react-native';
import awsExports from './aws-exports';
Amplify.configure(awsExports);
function SignOutButton() {
const { signOut } = useAuthenticator();
return ;
}
function App() {
return (
);
}
export default App;
`,
};
const languages = {
react: 'jsx',
angular: 'javascript', // is this the best primsa language?
vue: 'javascript',
flutter: 'dart',
'react-native': 'jsx',
};
const fileName = {
react: 'index.tsx',
angular: 'index.html',
vue: 'index.vue',
flutter: 'main.dart',
'react-native': 'App.jsx',
};
export const AuthenticationSection = ({ platform }) => {
const ref = useRef(null);
const entry = useIntersectionObserver(ref, {
threshold: 0.125,
freezeOnceVisible: true,
});
const isVisible = !!entry?.isIntersecting;
if (isVisible) {
trackScroll('Home#Authentication');
}
const hiddenOnMobile = useBreakpointValue({
base: false,
medium: true,
});
return (
Authentication made easy
Add authentication to your app in under 10 lines of code using the
Authenticator component. The Authenticator works seamlessly with the{' '}
Amplify CLI
{' '}
to automatically work with your backend, no extra
configuration needed! Customize every detail of the authentication
flow with themes, overrides, or bring your own UI with a headless
mode.
{platform === 'react-native' ? (
) : (
{platform === 'flutter' ? (
) : platform === 'react-native' ? null : (
)}
{hiddenOnMobile ? (
) : null}
)}
Get started with the Authenticator
);
};