如何禁用 aws amplify vue 身份验证器的注册 link?
How do I disable the sign up link for the aws amplify vue authenticator?
我正在使用 aws-amplify-vue
库中的 amplify-authenticator
组件来为我的应用程序启用身份验证。我试图弄清楚如何在前端禁用 "Create Account" link,但我似乎无法在文档或在线中找到任何内容。我见过一些用户通过 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>
您可以通过 "signInConfig" 对象隐藏 "sign up" 部分。
configurationOptions: any = {
signInConfig: {
isSignUpDisplayed: false
}
};
然后您可以将此对象作为 prop 传递给组件:
<amplify-authenticator
:authConfig="configurationOptions"
></amplify-authenticator>
注意: 您必须将配置对象设为本地 属性。如果配置是函数或计算 属性,则该配置将不起作用。您的完整解决方案如下:
<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>
我用简化的内联表达式得到了它:
<amplify-authenticator :authConfig="{ signInConfig: { isSignUpDisplayed: false } }" />
使用 @aws-amplify/auth ^3.2.6
和 @aws-amplify/ui-vue ^0.2.20
这按照 Sign In docs
中的记录工作
<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>
我试过了,在 Angular 8 中有效。
<amplify-authenticator>
<amplify-sign-in slot="sign-in" hide-sign-up="true"></amplify-sign-in>
</amplify-authenticator>
我正在使用 aws-amplify-vue
库中的 amplify-authenticator
组件来为我的应用程序启用身份验证。我试图弄清楚如何在前端禁用 "Create Account" link,但我似乎无法在文档或在线中找到任何内容。我见过一些用户通过 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>
您可以通过 "signInConfig" 对象隐藏 "sign up" 部分。
configurationOptions: any = {
signInConfig: {
isSignUpDisplayed: false
}
};
然后您可以将此对象作为 prop 传递给组件:
<amplify-authenticator
:authConfig="configurationOptions"
></amplify-authenticator>
注意: 您必须将配置对象设为本地 属性。如果配置是函数或计算 属性,则该配置将不起作用。您的完整解决方案如下:
<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>
我用简化的内联表达式得到了它:
<amplify-authenticator :authConfig="{ signInConfig: { isSignUpDisplayed: false } }" />
使用 @aws-amplify/auth ^3.2.6
和 @aws-amplify/ui-vue ^0.2.20
这按照 Sign In docs
<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>
我试过了,在 Angular 8 中有效。
<amplify-authenticator>
<amplify-sign-in slot="sign-in" hide-sign-up="true"></amplify-sign-in>
</amplify-authenticator>