# AWS Amplify Documentation AWS Amplify Documentation is the official documentation site for AWS Amplify, a comprehensive set of tools and services that enable frontend web and mobile developers to build full-stack applications on AWS. The documentation covers Amplify's core features including Authentication, Data/API, Storage, Functions, and more across multiple platforms (React, Next.js, Angular, Vue, React Native, Flutter, Android, Swift, and JavaScript). This repository is a Next.js-based documentation platform that uses MDX for content authoring, with a sophisticated component system for platform-specific content filtering, code block switching, and interactive UI elements. The site supports two major versions: Gen 2 (current/latest) at the root path and Gen 1 (legacy) under `/gen1/`. Content is organized by platform using dynamic routes (`[platform]`) and features reusable fragments for shared content across platforms. ## Creating Documentation Pages Every documentation page requires specific metadata and exports for proper rendering and navigation. Pages use MDX format with required meta fields for title, description, and supported platforms. ```mdx import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; export const meta = { title: 'Set up Amplify Auth', description: 'Learn how to set up and connect your backend resources for authentication in Amplify.', platforms: [ 'android', 'angular', 'flutter', 'javascript', 'nextjs', 'react', 'react-native', 'swift', 'vue' ] }; export function getStaticPaths() { return getCustomStaticPath(meta.platforms); } export function getStaticProps() { return { props: { meta } }; } Amplify Auth is powered by [Amazon Cognito](https://aws.amazon.com/cognito/). ## Getting Started To get started with defining your authentication resource: ```ts title="amplify/auth/resource.ts" import { defineAuth } from "@aws-amplify/backend" export const auth = defineAuth({ loginWith: { email: true, }, }) ``` ``` ## InlineFilter Component The InlineFilter component conditionally renders content based on the user's selected platform. Use this for platform-specific instructions, code examples, or feature availability notes within a single page. ```mdx ## JavaScript-specific Setup Install the Amplify libraries: ```bash npm install aws-amplify ``` Configure Amplify in your application: ```javascript import { Amplify } from 'aws-amplify'; import outputs from './amplify_outputs.json'; Amplify.configure(outputs); ``` ## Android-specific Setup Add the Amplify dependencies to your `build.gradle`: ```kotlin dependencies { implementation("com.amplifyframework:core:ANDROID_VERSION") implementation("com.amplifyframework:aws-auth-cognito:ANDROID_VERSION") } ``` ## iOS-specific Setup Add Amplify to your Package.swift: ```swift dependencies: [ .package(url: "https://github.com/aws-amplify/amplify-swift", from: "2.0.0") ] ``` ``` ## BlockSwitcher Component The BlockSwitcher component creates tabbed code blocks for showing multiple implementations (different languages, frameworks, or approaches) in a compact, switchable interface. ````mdx ```javascript import { signIn } from 'aws-amplify/auth'; async function handleSignIn({ username, password }) { try { const { isSignedIn, nextStep } = await signIn({ username, password }); console.log('Sign in successful:', isSignedIn); } catch (error) { console.log('Error signing in:', error); } } ``` ```typescript import { signIn, SignInInput, SignInOutput } from 'aws-amplify/auth'; async function handleSignIn({ username, password }: SignInInput): Promise { try { const result = await signIn({ username, password }); console.log('Sign in successful:', result.isSignedIn); return result; } catch (error) { console.log('Error signing in:', error); throw error; } } ``` ```kotlin suspend fun signIn(username: String, password: String) { try { val result = Amplify.Auth.signIn(username, password) if (result.isSignedIn) { Log.i("AuthQuickstart", "Sign in succeeded") } } catch (error: AuthException) { Log.e("AuthQuickstart", "Sign in failed", error) } } ``` ```` ## Accordion Component The Accordion component hides supplementary content until the reader expands it. Use for additional context, troubleshooting tips, advanced configurations, or optional deep-dives. ```mdx Access tokens are short-lived credentials that expire after a configured period (default: 1 hour). Amplify Auth automatically handles token refresh using refresh tokens when you make authenticated API calls. The refresh flow works as follows: 1. When an access token expires, Amplify intercepts the 401 response 2. Uses the refresh token to obtain new access and ID tokens 3. Retries the original request with the new tokens 4. If the refresh token is also expired, the user must sign in again You can customize token expiration in your auth resource: ```typescript export const auth = defineAuth({ loginWith: { email: true }, // Access tokens expire in 30 minutes accessTokenValidity: Duration.minutes(30), // Refresh tokens expire in 30 days refreshTokenValidity: Duration.days(30), }); ``` **UserNotFoundException**: The username does not exist in the user pool. Verify the user has completed registration. **NotAuthorizedException**: Incorrect password or the user is not confirmed. Check credentials and user status. **UserNotConfirmedException**: The user has not verified their account. Prompt them to check their email for a verification code. ```javascript import { confirmSignUp } from 'aws-amplify/auth'; // After user enters verification code await confirmSignUp({ username: 'user@example.com', confirmationCode: '123456' }); ``` ``` ## Callout Component The Callout component highlights important information, warnings, or notes. Use the `info` variant for general notes and `warning` for critical warnings. ```mdx **Note:** At a minimum you will need to pass a `loginWith` value to set up how your users sign in to your app. Signing in with email and password is configured by default if you do not provide any value. **Security Warning:** Never expose your AWS credentials in client-side code. Always use Amplify's authentication flow which handles credential management securely through Amazon Cognito. ## Example with code block You can configure multiple authentication methods: ```typescript export const auth = defineAuth({ loginWith: { email: true, phone: true, externalProviders: { google: { clientId: 'your-google-client-id', clientSecret: 'your-google-client-secret' } } } }); ``` ``` ## Fragments Component The Fragments component imports and conditionally renders platform-specific content from separate MDX files. Use when content varies significantly between platforms and would be unwieldy as inline filters. ```mdx import jsAuth from '/src/fragments/lib/auth/js/getting-started.mdx'; import androidAuth from '/src/fragments/lib/auth/android/getting-started.mdx'; import iosAuth from '/src/fragments/lib/auth/ios/getting-started.mdx'; import flutterAuth from '/src/fragments/lib/auth/flutter/getting-started.mdx'; ``` ## Video Component The Video component embeds MP4 videos with accessibility support and respects user motion preferences. Videos are stored in the `/public` directory. ```mdx