我正在使用库中的amplify-authenticator组件aws-amplify-vue为我的应用启用身份验证。我试图弄清楚如何禁用前端的“创建帐户”链接,但我似乎在文档或在线上找不到任何东西。我见过一些用户通过使用 css 隐藏它来禁用它的地方,以及一些用户能够使用 react 库禁用它的地方,但是我没有找到任何特定于 vue 库的东西。可能我只是缺少文档,但是有人知道如何从 vue amplify 身份验证器中删除注册功能吗?
零件
<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>
