Search code examples
javascripttypescriptaws-amplifyaws-amplify-vue

How do I disable the sign up link for the aws amplify vue authenticator?


I'm using the amplify-authenticator component from the aws-amplify-vue library to enable authentication for my app. I'm trying to figure out how to disable the "Create Account" link on the front end and I can't seem to find anything in the documentation or online. I've seen a few places where users disabled it by hiding it with css and a few places where users were able to disable it with the react library, but I haven't found anything specific for the vue library. It's possible I'm just missing the documentation, but does anyone know how to remove the sign up functionality from the vue amplify authenticator?

Component

enter image description here

<template>
  <v-container>
    <amplify-authenticator></amplify-authenticator>
  </v-container>
</template>

<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
import { Auth } from "aws-amplify";
import logger from "../logging";
import { components } from "aws-amplify-vue";
import { AmplifyEventBus } from "aws-amplify-vue";

@Component({
  components: {
    ...components
  }
})
export default class Login extends Vue {
  async created() {
    try {
      // This function throws an error if no user is logged in
      await Auth.currentAuthenticatedUser({ bypassCache: true });
      this.$router.push("/instruments");
    } catch (e) {
      logger.silly("No user currently logged in");

      AmplifyEventBus.$on("authState", async info => {
        logger.silly("signedIn");
        logger.silly(info);
        if (info === "signedIn") {
          const user = await Auth.currentAuthenticatedUser({
            bypassCache: true
          });
          this.$router.push("/instruments");
        } else {
          logger.error(`Failed to login`);
          alert("Failed to login");
        }
      });
    }
  }
}
</script>

<style scoped></style>

Update 1

Based on @asimpledevice's answer I tried the below without success:

<template>
  <v-container class="d-flex justify-center align-center">
    <amplify-authenticator
      :authConfig="authConfiguration"
    ></amplify-authenticator>
  </v-container>
</template>

<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
import { Auth } from "aws-amplify";
import StoreTypes from "../store-types";
import logger from "../logging";
import { components } from "aws-amplify-vue";
import { AmplifyEventBus } from "aws-amplify-vue";

@Component({
  components: {
    ...components
  }
})
export default class Login extends Vue {
  async mounted() {
    try {
      // This function throws an error if no user is logged in
      await Auth.currentAuthenticatedUser({ bypassCache: true });
      this.$router.push("/instruments");
    } catch (e) {
      const self = this;
      AmplifyEventBus.$on("authState", async info => {
        if (info === "signedIn") {
          this.$store.dispatch(StoreTypes.types.LOAD_CURRENT_USER);
          const nextLocation =
            self.$route.query.redirect !== null &&
            self.$route.query.redirect !== undefined
              ? (self.$route.query.redirect as string)
              : "/instruments";
          this.$router.push(nextLocation).catch(err => {});
        }
      });
    }
  }

  authConfiguration() {
    return {
      signInConfig: {
        isSignUpDisplayed: false
      }
    };
  }
}
</script>

Solution

  • You can hide the "sign up" section via the "signInConfig" object.

      configurationOptions: any = {
        signInConfig: {
          isSignUpDisplayed: false
        }
      };
    

    You can then pass this object in as a prop to the component:

        <amplify-authenticator
          :authConfig="configurationOptions"
        ></amplify-authenticator>
    

    NOTE: You must make the config object a local property. The config will not work if it is a function or computed property. Your full solution would be the following:

    <template>
      <v-container class="d-flex justify-center align-center">
        <amplify-authenticator
          :authConfig="configurationOptions"
        ></amplify-authenticator>
      </v-container>
    </template>
    
    <script lang="ts">
    import { Vue, Component } from "vue-property-decorator";
    import { Auth } from "aws-amplify";
    import StoreTypes from "../store-types";
    import logger from "../logging";
    import { components } from "aws-amplify-vue";
    import { AmplifyEventBus } from "aws-amplify-vue";
    
    @Component({
      components: {
        ...components
      }
    })
    export default class Login extends Vue {
      configurationOptions: any = {
        signInConfig: {
          isSignUpDisplayed: false
        }
      };
    
      async mounted() {
        try {
          // This function throws an error if no user is logged in
          await Auth.currentAuthenticatedUser({ bypassCache: true });
          this.$router.push("/instruments");
        } catch (e) {
          const self = this;
          AmplifyEventBus.$on("authState", async info => {
            if (info === "signedIn") {
              this.$store.dispatch(StoreTypes.types.LOAD_CURRENT_USER);
              const nextLocation =
                self.$route.query.redirect !== null &&
                self.$route.query.redirect !== undefined
                  ? (self.$route.query.redirect as string)
                  : "/instruments";
              this.$router.push(nextLocation).catch(err => {});
            }
          });
        }
      }
    }
    </script>
    
    <style></style>