javascript - 如何在放大中捕获来自 aws cognito pre signup lambda 的错误?
问题描述
我在 cognito 中使用预注册 lambda 触发器。某些情况下的 pre singup lambda 会引发异常(期望行为)。前端有以下代码:
await Vue.prototype.$auth
.federatedSignIn({
provider: provider
}).then((d) => {
console.log('success ', d)
}).catch((e) => {
console.log('here is and error', e)
})
}
当我运行代码时,我总是在 console.log 中看到成功消息( d 未定义),紧随其后,我还看到以下消息: 我想了解如何捕获此错误,我猜想放大记录它我,但我怎么能抓住它?
下面附上我的放大配置:
import Amplify, { Auth } from 'aws-amplify'
export default {
install (Vue) {
Amplify.configure({
Auth: {
region: config.auth.region,
userPoolId: config.auth.cognitoUserPoolId,
userPoolWebClientId: config.auth.cognitoClientId,
cookieStorage: {
domain: config.auth.cognitoCookieStorageDomain,
secure: config.auth.cognitoCookieStorageSecure
},
mandatorySignIn: false,
authenticationFlowType: 'USER_SRP_AUTH',
oauth: {
domain: config.auth.cognitoDomain,
scope: ['email', 'openid', 'aws.cognito.signin.user.admin'],
redirectSignIn: config.auth.cognitoSignInRedirectUrl,
redirectSignOut: config.auth.cognitoSignOutRedirectUrl,
responseType: 'code' // or 'token', note that REFRESH token will only be generated when the responseType is code
}
}
})
Vue.prototype.$auth = Auth
}
解决方案
您必须在 Pre-SignupTrigger(Lambda 函数)中处理此错误
假设您使用 amplify 生成了此设置 - 您可以在 Lambda 函数模板中本地执行此操作,您可以在文本编辑器中对其进行编辑。该函数的代码应位于amplify/backend/function/<functionname>
话虽如此,为了在默认 Amplify 实施之外更灵活地使用 Amazon Cognito,您可能需要考虑导入预先存在的 Amazon Cognito 用户池:https ://docs.amplify.aws/cli/auth/import
推荐阅读
- java - 无法将 ServiceClient 转换为 WSBindingProvider
- ios - 尝试调用请求的方法 validateAssets 时出错。(1272)
- erlang - 地图:put(Key,Value,Map)在erlang中不起作用
- java - 在eclipse错误中插入赋值运算符表达式以完成表达式
- typescript - 具有返回类型的打字稿查找类型
- go - Go中一对圆括号语法表达式是什么意思?
- google-apps-script - 附加菜单不出现
- julia - 如何在 Julia 中将矩阵漂亮地打印到字符串?
- flutter - 如何通过主题更改 Flutter 中抽屉的标准汉堡菜单图标的大小
- postgresql - 在 postgres 的事务中运行代码块