View a markdown version of this page

Managed sign-in page - AWS Amplify

Managed sign-in page

Amplify backend auth can serve a managed sign-in page under <backend URL>/auth/ui/, with sign-in, sign-up and password reset. The sign-in page has an option for each method that you turn on in your auth settings: email and password, a "Continue with" button for each social or OAuth provider, a passkey, and an emailed sign-in code or link. Users with two-step verification enter their second step on the same page. The sign-up page creates accounts with email and password only. For the social providers that the page can display, see Social sign-in and OAuth. Its tab title and headings display your appName. Your app sends users to the page, and they come back signed in.

The following image shows the sign-in page for an app named Acme Notes, with email and password, Google and GitHub turned on.

The managed sign-in page titled Sign in to Acme Notes, with email and password fields, a Forgot password? link, a Sign in button, Continue with Google and Continue with GitHub buttons, and a Sign up link

Turn on the managed sign-in page

The page is off by default, and its URL returns 404. A request without your publishable key gets 401 invalid_credential whether the page is on or off. To turn it on, set platform.hostedUi.enabled to true in the auth block of amplify.jsonc. For how the auth block works, see Auth configuration.

// amplify.jsonc { "backend": { "auth": { "appName": "Acme Notes", "emailAndPassword": { "enabled": true }, "platform": { "hostedUi": { "enabled": true } } } } }

Run aws amplifygen3 local run again to apply the change locally, or aws amplifygen3 deploy to apply it to an environment.

Send users to the page

To send a user to the page, open the URL that auth.hostedSignInUrl returns.

Browser code gets AMPLIFY_BACKEND_URL and AMPLIFY_BACKEND_PUBLISHABLE_KEY only when your framework inlines them as your app builds, such as with a Vite define. For more information, see the client SDK README on GitHub.

import { createClient } from '@aws-amplifygen3/backend-client-js' const backend = createClient(import.meta.env.AMPLIFY_BACKEND_URL, import.meta.env.AMPLIFY_BACKEND_PUBLISHABLE_KEY) export function signIn() { location.assign(backend.auth.hostedSignInUrl({ redirectUri: `${location.origin}/notes`, // required: absolute URL on a trusted origin // page: 'sign-up', // optional: opens sign-up instead of sign-in // lang: 'es', // optional: 'en', 'es' or 'zh' })) }

hostedSignInUrl puts your publishable key in the URL, so create the client with the publishable key. The page doesn’t load in a frame, so open it in the same tab, as in the example.

Get the signed-in user

The page returns the user to redirectUri. To read the signed-in user on that page, call getSession.

export async function currentUser() { const { data: { session } } = await backend.auth.getSession() return session?.user ?? null }

A deployed app uses token mode by default, because its backend is on another host. In token mode, the browser first returns to the root page of the redirectUri origin. Your root page must create the client, and the client then opens redirectUri. If the code is redeemed more than 2 minutes later, the user stays signed out: the client still opens redirectUri, returns no error and logs only a console warning. So check for a session on that page, and send a signed-out user back to sign in. For more information about token mode, see User sessions.

Note

If your app uses an older @aws-amplifygen3/auth-js, users stay on the root page and don’t reach redirectUri. Update it and @aws-amplifygen3/backend-client-js.

Choose the language

The page displays in English, Spanish or Simplified Chinese. To choose one, pass lang with en, es or zh. hostedSignInUrl throws an error for any other value. Without lang, the page uses the browser’s languages, then English.

Allow the return address

redirectUri must be an absolute URL, or hostedSignInUrl throws an error. The page answers 400 to a redirectUri whose origin the backend doesn’t trust. Amplify trusts the following origins without a trustedOrigins entry:

  • Your environment’s URL, its custom domains and the URLs of its recent successful deployments, up to 100 hosts in all. Amplify sends this list to the backend at each deployment, and when you add or remove a custom domain or an environment URL.

  • Locally, the dev server that aws amplifygen3 local run starts.

  • The backend’s own URL.

To return users to an older preview URL or a site that AWS Amplify doesn’t host, add its exact origin to trustedOrigins. A wildcard entry lets the page open, but in token mode, the default for a deployed app, the return after sign-in needs the exact origin. For more information about trusted origins, see Auth configuration.

Match your app’s look

To use your own colors, logo and layout, build your own sign-in screens with the client SDK. auth.signIn and auth.signUp call the same backend, and auth.getMethods() returns the sign-in methods to show.

The page’s wording and HTML can change, so don’t write tests that depend on them.

Settings

Setting in backend.auth Values Default

platform.hostedUi.enabled

true serves the page, and false or omitted returns 404 to a request with your publishable key

Off

appName

The name in the page’s tab title and headings

App

trustedOrigins

Other exact origins that the page can return users to

None

Errors

Response When

401 invalid_credential

The request has no publishable key

404

The page is off

400 "This sign-in link is not valid"

The link has no redirectUri, or redirectUri is on an origin that the backend doesn’t trust

400 "This language is not supported"

The link’s lang isn’t en, es, or zh. The page names the languages that it serves

INVALID_REDIRECT_URI on the page after sign-in

In token mode, only a wildcard trustedOrigins entry covers redirectUri. Add the exact origin