标签: amplifyjs

在 GatsbyJS 上获取 URL 参数

有没有办法检索在 GatsbyJS 上构建的项目页面上传递的 url 参数?我正在尝试使用 AWS 在我的页面上实现密码重置功能,但他们只能通过发送到用户电子邮件的链接发送参数。

所以流程是这样的:

用户触发忘记密码 -> AWS 通过链接向用户发送电子邮件 -> 链接使用参数定向到我的页面 -> 重置密码表单自动使用传递的参数填充字段

更新

这是我的 App.js 代码:

import { Router } from "@reach/router"


const App = () => (
  <Layout>
    <Router>
      <Login path="signin" exact component={Login} />
      <Resources path="api/resources" exact component={Resources} />
      <Verify path="verify" exact component={Verify} />
      <Forgot path="forgot" exact component={Forgot} />
      <Reset path="account/reset/:code" exact component={Reset}/>
    </Router>
  </Layout>
)

export default App;
Run Code Online (Sandbox Code Playgroud)

重置.js:

export default class ResetForm extends Component {
    constructor(props) {
        super(props);

        this.state = {
            password: "", …
Run Code Online (Sandbox Code Playgroud)

javascript amplifyjs amazon-cognito gatsby aws-amplify

11
推荐指数
2
解决办法
2万
查看次数

Amplify.js - 类似CRUD的网址

我正在使用amplify.request,我希望在向服务器发送数据和从服务器发送数据时使用类似CRUD的URL.这是一个例子:

定义资源

resources = {
"document_create"           : ['/d/crud/',           "POST"],
"document_read"             : ['/d/crud/{id}',       "GET"],
"document_update"           : ['/d/crud/{id}',       "PUT"],
"document_delete"           : ['/d/crud/{id}',       "DELETE"]
};

$.each(resources, function (resource, settings) {
  definition = {
    url     : settings[0],
    type    : settings[1],
    dataType: "json",  // what comes back
    decoder : 'jsend',
    contentType: 'application/json' // what goes there
  };

  amplify.request.define(resource, "ajax", definition);
});
Run Code Online (Sandbox Code Playgroud)

使用资源

function make_request(resource, params, success_cb, error_cb) {
 if (this.is_post(resource)) {
   // this.is_post is a test, defined elsewhere, to see if this is …
Run Code Online (Sandbox Code Playgroud)

javascript amplifyjs

10
推荐指数
2
解决办法
2816
查看次数

aws-amplify-react 和@aws-amplify/ui-react 有什么区别?

我看到很多文档和地方说要使用,aws-amplify-react但在文档中开始使用 react 我看到这个包@aws-amplify/ui-react使用模块withAuthenticationaws-amplify-react也有)

它们之间有什么区别?我应该什么时候用aws-amplify-react,什么时候用@aws-amplify/ui-react

javascript amplifyjs reactjs aws-amplify

10
推荐指数
1
解决办法
1069
查看次数

放大 403 也会出现 CORS 错误

通过 Amplify CLI 添加了一个 API,该 API 调用读取 dynamo 表的 lambda。

在 AWS 中部署后,它运行良好。今天早上它抛出 403 错误,没有进行任何更改:

获取 https://xxnxxtfxx.execute-api.eu-west-1.amazonaws.com/Prod/items 403

在' https://xxnxxtfxx.execute-api.eu-west-1.amazonaws.com/Prod/items ' from origin'' http://myproject-20181130113531--hostingbucket.s3-website-eu-访问 XMLHttpRequest west-1.amazonaws.com '' 已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。

观察/行动

  • 确保在 API Gateway 上启用 CORS,重新部署 API。

  • 从 API Gateway 测试 API 成功,它正确调用了 Lambda 函数

  • Amplify 服务确实创建了用户对象并保存在 localstorage 中
  • 在开发人员工具下调用 OPTIONS 看起来也不错:

    通用设置:

  • 请求网址:https : //xxnxxtfxx.execute-api.eu-west-1.amazonaws.com/Prod/items

  • 请求方法:OPTIONS
  • 状态码:200

    响应头:

  • access-control-allow-headers: Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token
  • 访问控制允许方法:DELETE、GET、HEAD、OPTIONS、PATCH、POST、PUT
  • 访问控制允许来源:*`

想知道为什么 403 会出现 CORS 错误。有什么想法吗?让我感到困惑和害怕的是,在我醒来后几个小时没有任何变化,事情就失败了:-(

amazon-web-services amplifyjs aws-amplify

8
推荐指数
1
解决办法
2744
查看次数

AWS Amplify:confirmSignUp 后,自动登录用户的最佳实践是什么?

概述:

用户收到验证码后,输入验证码,则Account Status变为CONFIRMED。现在注册过程已完成,我想在之后自动登录用户。将用户重定向到登录页面以让用户输入信息并登录似乎效率低下且多余。

可能的选项:

  1. 使用注册过程中的email和,然后分派操作来登录用户。passwordsignIn
  2. confirmSignUp为和找到一种组合方法signIn,这将类似于confirmSignUpAndSignIn(如果存在方法)。我查看了AWS 文档 和 Amplify-js Github Repo 的问题,但只发现其他人也遇到了类似的困境,但没有明显的解决方案。
  3. 使用AWS Amplify Hub(身份验证侦听器),但用户确认注册时不会发出任何事件。confirmSignUp发出事件是有意义的,但事实并非如此。(见下文)

AWS Hub监听器:

我正在使用AWS Amplify Hub(身份验证侦听器),发出的唯一事件是文档中的以下事件:

case 'signIn':
    logger.error('user signed in'); //[ERROR] My-Logger - user signed in
    break;
case 'signUp':
    logger.error('user signed up');
    break;
case 'signOut':
    logger.error('user signed out');
    break;
case 'signIn_failure':
    logger.error('user sign in failed');
    break;
case 'configured':
    logger.error('the Auth module is configured');
Run Code Online (Sandbox Code Playgroud)

authentication amazon-web-services amplifyjs amazon-cognito aws-amplify

8
推荐指数
1
解决办法
3263
查看次数

AWS Cognito cookie 存储

我正在尝试将 Cognito 设置为使用 cookie 而不是 localStorage 作为凭据,以便我可以让用户在域之间登录,例如,egxfoo.com 和 y.foo.com。第一步是让它在本地主机上工作,但我被卡住了。

文件显示了一个简单的配置变化应该做的伎俩?

以下调试消息被提交到控制台:

[DEBUG] 37:08.223 AuthClass 
Object { idToken: {…}, refreshToken: {…}, accessToken: {…}, clockDrift: 0 }
ConsoleLogger.js:87

[DEBUG] 37:08.228 Credentials - No Cache module registered in Amplify ConsoleLogger.js:84

[DEBUG] 37:08.230 Credentials - set credentials from session ConsoleLogger.js:84

[DEBUG] 37:08.230 Credentials - No Cognito Federated Identity pool provided ConsoleLogger.js:84

[DEBUG] 37:08.230 AuthClass - cannot get cognito credentials No Cognito Federated Identity pool provided ConsoleLogger.js:94

[DEBUG] 37:08.231 AuthClass - Failed to …
Run Code Online (Sandbox Code Playgroud)

cookies amplifyjs aws-amplify

7
推荐指数
1
解决办法
6943
查看次数

如何清除amplify.store()?

我需要清除amplifyjs存储,删除所有键值.Smth类似于localStorage.clear().

提前致谢.

javascript amplifyjs

6
推荐指数
1
解决办法
2858
查看次数

AWS 使用 Vue 放大模块化导入

这可能是一个非 Vue 特有的“JavaScript”问题。我正在尝试将特定模块作为别名导入,但这似乎是不可能的。我的具体问题如下所示,尝试在 AWS Amplify 和 Vue 中使用模块化导入。这是创建 Vue 实例的“非模块化”版本。

import Amplify, * as AmplifyModules from 'aws-amplify'
import { AmplifyPlugin } from 'aws-amplify-vue'
import aws_exports from './aws-exports';

Amplify.configure(aws_exports)
Vue.use(AmplifyPlugin, AmplifyModules)
Run Code Online (Sandbox Code Playgroud)

我已经这样做了:

import Amplify from '@aws-amplify/core'
Run Code Online (Sandbox Code Playgroud)

但我不知道如何将 AmplifyModules 的子集传递给 Vue。我不断收到此错误:

Uncaught (in promise) TypeError: Cannot read property 'Logger' of undefined
at VueComponent._callee$ (aws-amplify-vue.common.js?19b2:3257)
at tryCatch (runtime.js?96cf:62)
at Generator.invoke [as _invoke] (runtime.js?96cf:288)
at Generator.prototype.(:8080/anonymous function) [as next] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (aws-amplify-vue.common.js?19b2:6805)
at _next (aws-amplify-vue.common.js?19b2:6827)
at eval (aws-amplify-vue.common.js?19b2:6834)
at new Promise ()
at …
Run Code Online (Sandbox Code Playgroud)

javascript amplifyjs vue.js vuejs2 aws-amplify

6
推荐指数
1
解决办法
1430
查看次数

放大:即使在 API 网关和 Lambda 标头中启用了 CORS,也会出现 CORS 标头“Access-Control-Allow-Origin”丢失错误

我正在使用 Amplify,并将我的 API 网关代理到 Lambda。我已经启用了 CORS/{proxy+}并部署了 API。在我的 Lambda 函数中,我在我的平凡函数中设置了适当的标头:

import json


def handler(event, context):
    print("received event:")
    print(event)
    return {
        "statusCode": 200,
        "headers": {
            "Access-Control-Allow-Credentials": True,
            "Access-Control-Allow-Headers": "Content-Type",
            "Access-Control-Allow-Methods": "OPTIONS,POST,GET",
            "Access-Control-Allow-Origin": "*",
        },
        "body": json.dumps(event),
    }

Run Code Online (Sandbox Code Playgroud)

此 Lambda 函数位于通过 Cognito 进行身份验证的 API 网关资源之后。

当我使用 Amplify 调用我的 API 时:

let myInit = {
          headers: {
            Authorization: `Bearer ${(await Auth.currentSession())
              .getIdToken()
              .getJwtToken()}`
          }
        }; 

API.get("adminapi", "/admin", myInit) ...

Run Code Online (Sandbox Code Playgroud)

我的GET请求中缺少可怕的 CORS 标头“Access-Control-Allow-Origin” :

Cross-Origin Request Blocked: The Same Origin Policy …

cors amplifyjs aws-amplify aws-amplify-vue

6
推荐指数
2
解决办法
1万
查看次数

AWS Amplify - 是否有 API 可以验证使用忘记密码发送的代码并在验证后更改密码?

我使用 cognito 用户池进行用户管理,并使用忘记密码的流程将确认代码发送给用户。出于 UI 目的,我需要验证调用 API ForgotPassword 时发送的代码,但尚未发送新密码。我需要在“忘记密码”和“确认忘记密码”之间有一个中间步骤。

下面的函数是发送代码的函数:

Auth.forgotPassword(username)
Run Code Online (Sandbox Code Playgroud)

此功能正在使用发送的代码重置密码(如果代码无效,则会通知我)

Auth.forgotPasswordSubmit(username, code, new_password)
Run Code Online (Sandbox Code Playgroud)

是否可以仅验证使用现有 API 发送的代码?

这里有一个包含信息的链接: https ://docs.amplify.aws/lib/auth/manageusers/q/platform/js#forgot-password

javascript amplifyjs aws-amplify aws-amplify-sdk-js

6
推荐指数
0
解决办法
544
查看次数