ค้นหาเว็บไซต์

javascript - ฉันจะปิดใช้งานลิงก์สมัครสมาชิกสำหรับ aws amplify vue authenticator ได้อย่างไร?


ฉันกำลังใช้คอมโพเนนต์ amplify-authenticator จากไลบรารี aws-amplify-vue เพื่อเปิดใช้งานการรับรองตัวตนสำหรับแอปของฉัน ฉันกำลังพยายามหาวิธีปิดการใช้งานลิงก์ "สร้างบัญชี" ในหน้าฟรอนต์เอนด์ แต่ดูเหมือนว่าจะหาอะไรในเอกสารหรือออนไลน์ไม่เจอ ฉันเห็นบางที่ที่ผู้ใช้ปิดมันโดยซ่อนด้วย CSS และบางที่ผู้ใช้สามารถปิดมันโดยใช้ไลบรารี React แต่ฉันยังไม่เจออะไรที่เฉพาะเจาะจงสำหรับไลบรารี Vue เป็นไปได้ว่าฉันอาจพลาดเอกสาร แต่มีใครรู้วิธีลบฟังก์ชันการสมัครสมาชิกออกจาก Vue Amplify Authenticator ไหม?

ส่วนประกอบ

<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>

อัปเดต 1

ตามคำตอบของ @asimpledevice ฉันได้ลองทำดังต่อไปนี้แต่ไม่สำเร็จ:

<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>

คำตอบ #1

คุณสามารถซ่อนส่วน "ลงทะเบียน" ผ่านวัตถุ "signInConfig" ได้

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

คุณสามารถส่งอ็อบเจ็กต์นี้เข้าไปเป็นพร็อพให้กับคอมโพเนนต์ได้ดังนี้:

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

หมายเหตุ: คุณต้องทำให้วัตถุ config เป็นคุณสมบัติท้องถิ่น config จะไม่ทำงานถ้ามันเป็นฟังก์ชันหรือคุณสมบัติคำนวณ วิธีแก้ปัญหาเต็มของคุณจะเป็นดังต่อไปนี้:

<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>

คำตอบ #2

กับ @aws-amplify/auth ^3.2.6 และ @aws-amplify/ui-vue ^0.2.20 สิ่งนี้ทำงานตามที่ระบุไว้ในเอกสารการเข้าสู่ระบบ

<template>
  <div>
    <amplify-authenticator username-alias="email">
      <amplify-sign-in slot="sign-in" :hide-sign-up="true"
        username-alias="email">
      </amplify-sign-in>
    </amplify-authenticator>
  </div>
</template>

บทความที่เกี่ยวข้อง