You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Amplify React下Cognito登录页移除注册入口配置问题

Amplify Cognito 移除登录页注册入口配置方案

后端配置(生成携带AllowAdminCreateUserOnly属性的CF模板)

你采用的amplify override auth方式是Amplify官方推荐的自定义资源配置方案,对应override.ts的配置完全正确:

import { AmplifyAuthCognitoStackTemplate } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyAuthCognitoStackTemplate) {
    resources.userPool.adminCreateUserConfig = {
        allowAdminCreateUserOnly: true,
    }
}

执行amplify push部署后,生成的CloudFormation模板会自动携带AdminCreateUserConfig.AllowAdminCreateUserOnly: True属性,你可以通过Cognito控制台查看用户池配置,确认Only allow administrators to create users选项已选中即代表后端配置生效。

React端Amplify UI配置(隐藏注册入口)

@aws-amplify/ui-react@2.x版本默认不会自动同步Cognito侧的用户注册策略来隐藏注册按钮,需要手动给Auth组件添加hideSignUp属性:

情况1:使用withAuthenticator高阶组件包裹应用

import { withAuthenticator } from '@aws-amplify/ui-react';
import '@aws-amplify/ui-react/styles.css';

function App() {
  // 应用原有逻辑
}

export default withAuthenticator(App, {
  hideSignUp: true
});

情况2:直接使用Authenticator组件

import { Authenticator } from '@aws-amplify/ui-react';
import '@aws-amplify/ui-react/styles.css';

function App() {
  return (
    <Authenticator hideSignUp>
      {({ signOut, user }) => (
        // 应用原有逻辑
      )}
    </Authenticator>
  );
}

添加该属性后,登录页的注册入口会完全隐藏,和后端Cognito的注册策略对齐。

内容的提问来源于stack exchange,提问作者zdenko.s

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 20:15:04