@@ -43,6 +43,7 @@ import {
4343 AttributeMapping ,
4444 AuthProps ,
4545 CustomAttribute ,
46+ CustomDomainOptions ,
4647 CustomSmsSender ,
4748 EmailLoginSettings ,
4849 ExternalProviderOptions ,
@@ -60,10 +61,7 @@ import {
6061 Certificate ,
6162 CertificateValidation ,
6263} from 'aws-cdk-lib/aws-certificatemanager' ;
63- import {
64- CloudFrontTarget ,
65- UserPoolDomainTarget ,
66- } from 'aws-cdk-lib/aws-route53-targets' ;
64+ import { UserPoolDomainTarget } from 'aws-cdk-lib/aws-route53-targets' ;
6765
6866type DefaultRoles = { auth : Role ; unAuth : Role } ;
6967type IdentityProviderSetupResult = {
@@ -869,6 +867,38 @@ export class AmplifyAuth
869867 return undefined ;
870868 } ;
871869
870+ private setupCustomDomain = (
871+ userPool : UserPool ,
872+ customDomainOptions : CustomDomainOptions ,
873+ ) => {
874+ const hostedZone = HostedZone . fromHostedZoneAttributes (
875+ this ,
876+ `${ this . name } HostedZone` ,
877+ customDomainOptions . hostedZone ,
878+ ) ;
879+
880+ const certificate = new Certificate ( this , `${ this . name } Certificate` , {
881+ domainName : customDomainOptions . domainName ,
882+ validation : CertificateValidation . fromDns ( hostedZone ) ,
883+ } ) ;
884+
885+ const customDomain = userPool . addDomain (
886+ `${ this . name } UserPoolCustomDomain` ,
887+ {
888+ customDomain : {
889+ domainName : customDomainOptions . domainName ,
890+ certificate,
891+ } ,
892+ } ,
893+ ) ;
894+
895+ new ARecord ( this , `${ this . name } ARecord` , {
896+ zone : hostedZone ,
897+ recordName : customDomainOptions . domainName ,
898+ target : RecordTarget . fromAlias ( new UserPoolDomainTarget ( customDomain ) ) ,
899+ } ) ;
900+ } ;
901+
872902 /**
873903 * Setup External Providers (OAuth/OIDC/SAML) and related settings
874904 * such as OAuth settings and User Pool Domains
@@ -1070,37 +1100,10 @@ export class AmplifyAuth
10701100 ) ;
10711101 }
10721102
1073- const stack = Stack . of ( this ) ;
1074-
1075- const hostedZone = HostedZone . fromHostedZoneAttributes (
1076- stack ,
1077- 'hostedZone' ,
1078- {
1079- hostedZoneId : 'Z00739961UF0WORM8EZIG' ,
1080- zoneName : 'goheim.com' ,
1081- } ,
1082- ) ;
1083-
1084- const certificate = new Certificate ( stack , 'certificate' , {
1085- domainName : 'auth.goheim.com' ,
1086- validation : CertificateValidation . fromDns ( hostedZone ) ,
1087- } ) ;
1088-
1089- const customDomain = this . userPool . addDomain (
1090- `${ this . name } UserPoolCustomDomain` ,
1091- {
1092- customDomain : {
1093- domainName : 'auth.goheim.com' ,
1094- certificate,
1095- } ,
1096- } ,
1097- ) ;
1098-
1099- new ARecord ( Stack . of ( this ) , `${ this . name } ARecord` , {
1100- zone : hostedZone ,
1101- recordName : 'auth.goheim.com' ,
1102- target : RecordTarget . fromAlias ( new UserPoolDomainTarget ( customDomain ) ) ,
1103- } ) ;
1103+ // Generate a custom domain if custom domain options are specified
1104+ if ( external . customDomainOptions ) {
1105+ this . setupCustomDomain ( this . userPool , external . customDomainOptions ) ;
1106+ }
11041107
11051108 // oauth settings for the UserPool client
11061109 result . oAuthSettings = {
0 commit comments