Authentication
AWS Amplify

How to use Amplify ?

Note: The quickframe template uses the firebase authentication system by default.

Step 2


_10
import { AuthContext } from "contexts/amplifyContext";
_10
_10
const useAuth = () => useContext(AuthContext);
_10
export default useAuth;

Step 3

login.jsx

_17
import useAuth from "hooks/useAuth";
_17
_17
const Login = () => {
_17
const { login } = useAuth();
_17
_17
const onLogin = async () => {
_17
await login("example@email.com", "pass123"); // Login crediential
_17
};
_17
_17
return (
_17
<Box>
_17
<Button onClick={onLogin}>Login</Button>
_17
</Box>
_17
);
_17
};
_17
_17
export default Login;

profile.jsx

_18
import useAuth from "hooks/useAuth";
_18
_18
const Profile = () => {
_18
const { user, isAuthenticated, logout } = useAuth();
_18
_18
if (isAuthenticated && user) {
_18
return (
_18
<Box>
_18
<Typography>Email : {user.email}</Typography>
_18
<Button onClick={logout}>logout</Button>
_18
</Box>
_18
);
_18
}
_18
_18
return <Redirect to="/login" />;
_18
};
_18
_18
export default Profile;

How to delete from app ?

  • Delete the amplifyContext.jsx file from src/contexts folder
  • If you use this, you should also remove the AuthContext file from the src/hooks/useAuth.js file.
  • Remove the aws-exports.js file & amplify folder from the app root folder as well.
  • Remove the dependency aws-amplify

Reference