Skip to content

Amplify Auth Usage

0

I have a basic React/Vite app built out that I have been able to deploy through Github on Amplify. I'm trying to set up Authentication through Amplify but am running into issues.

There are a couple of steps in the Amplify console under "All apps/app name/main:Authentication" that I have followed that should disappear, leaving the authentication console once it is implemented correctly (as it does when I cloned the template found here: https://docs.amplify.aws/react/start/quickstart/").

  1. a folder called "/amplify" installed by the command "npm create amplify@latest" in the root of my folder (ie same level as src, public, etc)
  2. a sandbox running with the command "npx ampx sandbox"
  3. and the most recent version pushed to git and thus redeployed

I'd rather not edit the files in the clone to match my already build app. In addition, the clone is written with .tsx files while I've been using .jsx files so I'm not sure if that has an effect (files in "/amplify" are .ts).

1 Answer
0

Amplify's Authenticator UI component can help you implement authentication in your React/Vite app without having to build the sign-in flow from scratch. The file extension difference (.jsx vs .tsx) shouldn't be an issue for implementing Amplify Auth.

To properly set up authentication in your existing React/Vite app, follow these steps:

  1. Create the amplify folder structure using npm create amplify@latest as you've already done.

  2. Configure your authentication resource in amplify/auth/resource.ts to define your sign-in methods (email, phone numbers, or external providers).

  3. Deploy your authentication resource using npx ampx sandbox. This will generate an amplify_outputs.json file that connects your frontend to the backend resources.

  4. Install the Authenticator UI component:

npm add @aws-amplify/ui-react
  1. Add the Authenticator component to your main app file. Since you're using .jsx files, you would add it to your main app component (similar to how it would be added to _app.tsx in a Next.js project).

Once you've added the Authenticator component to your app, you should be able to test the sign-up, sign-in, and sign-out functionality. You can also customize the Authenticator component to match your app's styling.

The key is ensuring that the Authenticator component is properly connected to your backend resources through the configuration in the amplify folder and the generated outputs file.
Sources
Set up Amplify Auth - AWS Amplify Gen 2 Documentation
Set up Amplify Auth - AWS Amplify Gen 2 Documentation
Set up Amplify Auth - AWS Amplify Gen 2 Documentation

answered a year ago

  • Partially solved. The main issue in establishing the authenticator was that the program sometimes includes amplify_outputs.json in the gitignore file. I copied the file into src and git added the file to force it. However, I'm still unable to customize the Authentication from the Amplify console even after starting the sandbox and pushing my most recent build through Github Desktop. Right now the authentication shows up and I'm able to log into it. But it's ugly and I am not sure how to personalize it.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.