Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 3x 5x 3x 3x 3x 3x 3x | import { Amplify } from 'aws-amplify'
const cognitoDomain = import.meta.env.VITE_COGNITO_DOMAIN
function trimTrailingSlash(url: string): string {
return url.replace(/\/$/, '')
}
const runtimeOrigin = trimTrailingSlash(window.location.origin)
const configuredAppUrl = import.meta.env.VITE_APP_URL
? trimTrailingSlash(import.meta.env.VITE_APP_URL)
: ''
// Cognito/Amplify validates that the OAuth flow is initiated from an allowed origin.
// Always include the current runtime origin, and also include VITE_APP_URL when set.
const signInRedirects = Array.from(
new Set([`${runtimeOrigin}/`, ...(configuredAppUrl ? [`${configuredAppUrl}/`] : [])])
)
const signOutRedirects = Array.from(
new Set([`${runtimeOrigin}/login`, ...(configuredAppUrl ? [`${configuredAppUrl}/login`] : [])])
)
Amplify.configure({
Auth: {
Cognito: {
userPoolId: import.meta.env.VITE_COGNITO_USER_POOL_ID || '',
userPoolClientId: import.meta.env.VITE_COGNITO_CLIENT_ID || '',
signUpVerificationMethod: 'code',
loginWith: {
email: true,
// OAuth is only configured when a Cognito domain is provided (social login)
...(cognitoDomain
? {
oauth: {
domain: cognitoDomain,
scopes: ['email', 'openid', 'profile', 'aws.cognito.signin.user.admin'],
redirectSignIn: signInRedirects,
redirectSignOut: signOutRedirects,
responseType: 'code' as const
}
}
: {})
}
}
}
})
|