All Projects β†’ elkevinwolf β†’ Amplified

elkevinwolf / Amplified

Licence: mit
🎣 AWS Amplify libraries wrapped with React hooks

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Amplified

aws-amplify-react-custom-ui
Building a Custom UI Authentication For AWS Amplify
Stars: ✭ 21 (-80.73%)
Mutual labels:  aws-amplify
Aws Amplify Vue
A Vue.js starter app integrated with AWS Amplify
Stars: ✭ 359 (+229.36%)
Mutual labels:  aws-amplify
Aws Amplify React Native Events App Workshop
This is a self-paced workshop designed for developers who want to build a React Native mobile application using mobile services from Amazon Web Services (AWS).
Stars: ✭ 59 (-45.87%)
Mutual labels:  aws-amplify
aws-cognito-next
Authentication helpers for AWS Cognito in next.js
Stars: ✭ 64 (-41.28%)
Mutual labels:  aws-amplify
Gatsby Auth Starter Aws Amplify
Starter Project with Authentication with Gatsby & AWS Amplify
Stars: ✭ 306 (+180.73%)
Mutual labels:  aws-amplify
Aws Appsync Chat
Real-Time Offline Ready Chat App written with GraphQL, AWS AppSync, & AWS Amplify
Stars: ✭ 522 (+378.9%)
Mutual labels:  aws-amplify
serverless-web-app-example
Serverless React Web App Example
Stars: ✭ 41 (-62.39%)
Mutual labels:  aws-amplify
Hype Beats
Real-time Collaborative Beatbox with React & GraphQL
Stars: ✭ 100 (-8.26%)
Mutual labels:  aws-amplify
Devlopr Jekyll
Build and Deploy your Static Site πŸš€ using this beautiful Jekyll Framework/Theme built for Creatives
Stars: ✭ 309 (+183.49%)
Mutual labels:  aws-amplify
Amplify Js
A declarative JavaScript library for application development using cloud services.
Stars: ✭ 8,539 (+7733.94%)
Mutual labels:  aws-amplify
amplify-codegen-ui
Generate React components for use in an AWS Amplify project.
Stars: ✭ 14 (-87.16%)
Mutual labels:  aws-amplify
ausg-2020-handson-appsync
AWS AppSync둜 λ§Œλ“œλŠ” μ„œλ²„λ¦¬μŠ€ GraphQL μ„œλΉ„μŠ€ (ft. AWS Amplify)
Stars: ✭ 13 (-88.07%)
Mutual labels:  aws-amplify
Aws Mobile React Sample
A React Starter App that displays how web developers can integrate their front end with AWS on the backend. The App interacts with AWS Cognito, API Gateway, Lambda and DynamoDB on the backend.
Stars: ✭ 650 (+496.33%)
Mutual labels:  aws-amplify
aws-sync-routes
Synchronizes the specified route from the main/default route table to all custom route tables in the VPC.
Stars: ✭ 16 (-85.32%)
Mutual labels:  aws-amplify
Aws Amplify Ecommerce
Learn how to integrate AWS Amplify and Amazon Pinpoint to create a retail website. You use the event data that's generated by customers activities on your site to send custom-tailored emails, creating a curated, omnichannel experience.
Stars: ✭ 71 (-34.86%)
Mutual labels:  aws-amplify
react-native-custom-authentication
Custom authentication flow using React Native and AWS Amplify
Stars: ✭ 27 (-75.23%)
Mutual labels:  aws-amplify
Aws Mobile Appsync Chat Starter Angular
GraphQL starter progressive web application (PWA) with Realtime and Offline functionality using AWS AppSync
Stars: ✭ 449 (+311.93%)
Mutual labels:  aws-amplify
Reactnativeauth
Mobile user authentication flow with React Native, Expo, and AWS Amplify: Sign In, Sign Up, Confirm Sign Up, Forget Password, Reset Password.
Stars: ✭ 108 (-0.92%)
Mutual labels:  aws-amplify
This Or That
This or that - Real-time atomic voting app built with AWS Amplify
Stars: ✭ 87 (-20.18%)
Mutual labels:  aws-amplify
Conference App In A Box
Full stack & cross platform app customizable & themeable for any event or conference.
Stars: ✭ 693 (+535.78%)
Mutual labels:  aws-amplify

🎣 Amplified

AWS Amplify libraries wrapped with React hooks.

Getting started

  1. Install
yarn add amplified
  1. Wrap your application with <AmplifyProvider />
import React from "react";
import ReactDOM from "react-dom";
import { AmplifyProvider } from "amplified";

import awsExports from "./aws-exports";
import App from "./app";

ReactDOM.render(
  <React.StrictMode>
    <AmplifyProvider config={awsExports}>
      <App />
    </AmplifyProvider>
  </React.StrictMode>,
  document.getElementById("root")
);

Table of Contents

Libraries

Auth

<Auth.Provider />

If your are using authentication features in your app, wrap it with <Auth.Provider /> in order to react to authentication state changes.

Uses data fetching techniques to asynchronously get the current user.

Usage

import React from "react";
import ReactDOM from "react-dom";
import { AmplifyProvider, Auth } from "amplified";

import awsExports from "./aws-exports";
import App from "./app";

ReactDOM.render(
  <React.StrictMode>
    <AmplifyProvider config={awsExports}>
      <Auth.Provider>
        <App />
      </Auth.Provider>
    </AmplifyProvider>
  </React.StrictMode>,
  document.getElementById("root")
);

Auth.useCurrentUser(): CognitoUser | null

Returns the current authenticated user, if any. Its value changes automatically according to the current authentication state.

⚠️ Your app must be wrapped with <Auth.Provider /> or you will get an error if you try to useCurrentUser.

Usage

import React from "react";
import { Auth } from "amplified";

import Authenticated from "views/authenticated";
import Unauthenticated from "views/unauthenticated";

const App: React.FC = () => {
  const currentUser = Auth.useCurrentUser();

  return currentUser ? (
    <div>Hola, {currentUser.getUsername()}</div>
  ) : (
    <div>Please sign in!</div>
  );
};

export default App;

Auth.useSignIn(): [signIn, signInState]

Returns an async callback around Auth.signIn.

Usage

import React from "react";
import { Auth } from "amplified";

const SignIn: React.FC = () => {
  const [signIn, signInState] = Auth.useSignIn();
  const [username, setUsername] = React.useState("");
  const [password, setPassword] = React.useState("");

  React.useEffect(() => {
    if (signInState.wasSuccessful) {
      alert("Successfully signed in");
    }
  }, [signInState.wasSuccessful]);

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    signIn(username, password);
  };

  return (
    <form onSubmit={handleSubmit}>
      {signInState.error ? <div>{signInState.error.message}</div> : null}
      <input
        type="text"
        placeholder="Username"
        value={username}
        onChange={e => setUsername(e.target.value)}
      />
      <input
        type="password"
        placeholder="Password"
        value={password}
        onChange={e => setPassword(e.target.value)}
      />
      <button type="submit" disabled={signInState.isLoading}>
        Sign In
      </button>
    </form>
  );
};

export default SignIn;

Auth.useSignOut(): [signOut, signOutState]

Returns an async callback around Auth.signOut.

Usage

import React from "react";
import { Auth } from "amplified";

const Authenticated: React.FC = () => {
  const currentUser = Auth.useCurrentUser();
  const [submitSignOut, signOut] = Auth.useSignOut();

  return (
    <div>
      <h1>{currentUser?.getUsername()}</h1>
      <button
        type="button"
        disabled={signOut.isLoading}
        onClick={() => submitSignOut()}
      >
        Sign Out
      </button>
    </div>
  );
};

export default Authenticated;

Auth.useSignUp(): [signUp, signUpState]

Returns an async callback around Auth.signUp.

Usage

import React from "react";
import { Auth } from "amplified";

const SignUp: React.FC = () => {
  const [signUp, signUpState] = Auth.useSignUp();
  const [username, setUsername] = React.useState("");
  const [email, setEmail] = React.useState("");
  const [password, setPassword] = React.useState("");

  React.useEffect(() => {
    if (signUpState.wasSuccessful) {
      alert("Successfully signed up");
    }
  }, [signUpState.wasSuccessful]);

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    signUp({ username, password, attributes: { email } });
  };

  return (
    <form onSubmit={handleSubmit}>
      {signUpState.error ? <div>{signUpState.error.message}</div> : null}
      <input
        type="text"
        placeholder="Username"
        value={username}
        onChange={e => setUsername(e.target.value)}
      />
      <input
        type="text"
        placeholder="Email"
        value={email}
        onChange={e => setEmail(e.target.value)}
      />
      <input
        type="password"
        placeholder="Password"
        value={password}
        onChange={e => setPassword(e.target.value)}
      />
      <button type="submit" disabled={signUpState.isLoading}>
        Sign Up
      </button>
    </form>
  );
};

export default SignUp;

Auth.useConfirmSignUp(): [confirmSignUp, confirmSignUpState]

Returns an async callback around Auth.confirmSignUp.

Usage

import React from "react";
import { Auth } from "amplified";

const ConfirmSignUp: React.FC = () => {
  const [confirmSignUp, confirmSignUpState] = Auth.useConfirmSignUp();
  const [username, setUsername] = React.useState("");
  const [code, setCode] = React.useState("");

  React.useEffect(() => {
    if (confirmSignUpState.wasSuccessful) {
      alert("Account confirmed");
    }
  }, [confirmSignUpState.wasSuccessful]);

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    confirmSignUp(username, code);
  };

  return (
    <form onSubmit={handleSubmit}>
      {confirmSignUpState.error ? (
        <div>{confirmSignUpState.error.message}</div>
      ) : null}
      <input
        type="text"
        placeholder="Username"
        value={username}
        onChange={e => setUsername(e.target.value)}
      />
      <input
        type="text"
        placeholder="Code"
        value={code}
        onChange={e => setCode(e.target.value)}
      />
      <button type="submit" disabled={confirmSignUpState.isLoading}>
        Confirm Sign Up
      </button>
    </form>
  );
};

export default ConfirmSignUp;

Auth.useForgotPassword(): [forgotPassword, forgotPasswordState]

Returns an async callback around Auth.forgotPassword.

Usage

import React from "react";
import { Auth } from "amplified";

const ForgotPassword: React.FC = () => {
  const [forgotPassword, forgotPasswordState] = Auth.useForgotPassword();
  const [username, setUsername] = React.useState("");

  React.useEffect(() => {
    if (forgotPasswordState.wasSuccessful) {
      alert("Verification code sent");
    }
  }, [forgotPasswordState.wasSuccessful]);

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    forgotPassword(username);
  };

  return (
    <form onSubmit={handleSubmit}>
      {forgotPasswordState.error ? (
        <div>{forgotPasswordState.error.message}</div>
      ) : null}
      <input
        type="text"
        placeholder="Username"
        value={username}
        onChange={e => setUsername(e.target.value)}
      />
      <button type="submit" disabled={forgotPasswordState.isLoading}>
        Send verification code
      </button>
    </form>
  );
};

export default ForgotPassword;

Auth.useForgotPasswordSubmit(): [forgotPasswordSubmit, forgotPasswordSubmitState]

Returns an async callback around Auth.forgotPasswordSubmit.

Usage

import React from "react";
import { Auth } from "amplified";

const ResetPassword: React.FC = () => {
  const [resetPassword, resetPasswordState] = Auth.useForgotPasswordSubmit();
  const [username, setUsername] = React.useState("");
  const [code, setCode] = React.useState("");
  const [password, setPassword] = React.useState("");

  React.useEffect(() => {
    if (resetPasswordState.wasSuccessful) {
      alert("Password successfuly changed");
    }
  }, [resetPasswordState.wasSuccessful]);

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    resetPassword(username, code, password);
  };

  return (
    <form onSubmit={handleSubmit}>
      {resetPasswordState.error ? (
        <div>{resetPasswordState.error.message}</div>
      ) : null}
      <input
        type="text"
        placeholder="Username"
        value={username}
        onChange={e => setUsername(e.target.value)}
      />
      <input
        type="text"
        placeholder="Code"
        value={code}
        onChange={e => setCode(e.target.value)}
      />
      <input
        type="password"
        placeholder="Password"
        value={password}
        onChange={e => setPassword(e.target.value)}
      />
      <button type="submit" disabled={resetPasswordState.isLoading}>
        Reset Password
      </button>
    </form>
  );
};

export default ResetPassword;

Concepts

Data fetching techniques

All remote data fetching happens through SWR, a library created by the Vercel team that uses advanced cache invalidation strategies.

Enabling Suspense

You can enable Suspense for Data Fetching by passing enableSuspense prop to <AmplifyProvider />.

Example

import React from "react";
import ReactDOM from "react-dom";
import { AmplifyProvider } from "amplified";

import awsExports from "./aws-exports";
import App from "./app";

ReactDOM.render(
  <React.StrictMode>
    <React.Suspense fallback={<div>Loading</div>}>
      <AmplifyProvider enableSuspense config={awsExports}>
        <App />
      </AmplifyProvider>
    </React.Suspense>
  </React.StrictMode>,
  document.getElementById("root")
);

Async callbacks

An async callback is a hook that receives a promise as an argument and returns an array containing two items: the wrapped promise and an execution state object that contains:

  1. isLoading: a boolean indicating if the promise is executing
  2. result: result value from the promise, if it succeeded
  3. error: error thrown from the promise, if it failed
  4. wasSuccessful: a boolean indicating if the promise execution was successful

Examples

Contributors


Kevin Wolf

πŸ“– πŸ’» πŸš‡

Contributing

If you have any question, suggestion or recommendation, please open an issue about it.

If you decided you want to introduce something to the project, please read contribution guidelines first.

Release

All the release process is automated and managed by the awesome package auto.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].