@@ -41,6 +41,11 @@ export interface OAuthCognitoConfig {
4141 * @default process.env.NUXT_OAUTH_COGNITO_REDIRECT_URL or current URL
4242 */
4343 redirectURL ?: string
44+ /**
45+ * AWS Cognito App Custom Domain – some pool configurations require this
46+ * @default ''
47+ */
48+ domain ?: string
4449}
4550
4651export function oauthCognitoEventHandler ( { config, onSuccess, onError } : OAuthConfig < OAuthCognitoConfig > ) {
@@ -59,8 +64,10 @@ export function oauthCognitoEventHandler({ config, onSuccess, onError }: OAuthCo
5964 return onError ( event , error )
6065 }
6166
62- const authorizationURL = `https://${ config . userPoolId } .auth.${ config . region } .amazoncognito.com/oauth2/authorize`
63- const tokenURL = `https://${ config . userPoolId } .auth.${ config . region } .amazoncognito.com/oauth2/token`
67+ const urlBase = config ?. domain || `${ config . userPoolId } .auth.${ config . region } .amazoncognito.com`
68+
69+ const authorizationURL = `https://${ urlBase } /oauth2/authorize`
70+ const tokenURL = `https://${ urlBase } /oauth2/token`
6471
6572 const redirectURL = config . redirectURL || getRequestURL ( event ) . href
6673 if ( ! code ) {
@@ -107,7 +114,7 @@ export function oauthCognitoEventHandler({ config, onSuccess, onError }: OAuthCo
107114 const accessToken = tokens . access_token
108115 // TODO: improve typing
109116 // eslint-disable-next-line @typescript-eslint/no-explicit-any
110- const user : any = await $fetch ( `https://${ config . userPoolId } .auth. ${ config . region } .amazoncognito.com /oauth2/userInfo` , {
117+ const user : any = await $fetch ( `https://${ urlBase } /oauth2/userInfo` , {
111118 headers : {
112119 Authorization : `${ tokenType } ${ accessToken } ` ,
113120 } ,
0 commit comments