升级软件包和手动时钟更改后 AWS-Amplify v6 时钟同步问题

问题描述 投票:0回答:1

我将

aws-amplify
^4.1.0
更新为
^6.0.13
,将
amazon-cognito-identity-js
^4.3.2
更新为
^6.3.7
。升级后,每当我调整机器的时钟时,请求同步就会失控,无法与服务器时间正确对齐——这是我们项目早期的一个遗留问题,之前由以下解决方案修复:

const syncAWSClock = async () => {
    const authenticatedUser = await Auth.currentAuthenticatedUser({bypassCache: true});
    const clockDrift = _get(authenticatedUser, 'signInUserSession.clockDrift', 0);
    const clockOffset = -(clockDrift * 1000);
    DateUtils.setClockOffset(clockOffset);
};

此修复已纳入我们的 API 请求处理程序中。但在新的 aws-amplify 版本中,此解决方法变得无法访问,似乎被自动处理程序所取代。奇怪的是,我注意到正确的 timeDrift 现在存储在 cookie 中。 the clockdrift stored correct in the cookies

我尝试通过执行此选项来修复它:

import * as AWS from 'aws-sdk';
AWS.config.update({ 
   correctClockSkew: true,
   systemClockOffset: 3603033
})

但它不起作用,我发现它更新了 AWS.config 文件中的右键。

有人遇到这个问题吗?

这是升级前配置文件的样子:

Amplify.configure({
        Auth: {
            mandatorySignIn: true,
            region: "region",
            userPoolId: "userPoolId",
            identityPoolId: "identityPoolId",
            userPoolWebClientId: "userPoolWebClientId",
            cookieStorage: {
                domain: window.location.hostname,
                secure: true,
                path: '/',
                expires: 7,
            },
            oauth: {
                domain: domainName,
                scope: ['email', 'aws.cognito.signin.user.admin', 'openid', 'profile'],
                redirectSignIn: publicUrl.origin,
                redirectSignOut: publicUrl.origin,
                responseType: 'code',
            },
        },
        Storage: {
            region: _get(s3Config, 'Region'),
            bucket: _get(s3Config, 'Bucket'),
           identityPoolId: "identityPoolId",
        },
        API: {
            endpoints: [
                {
                    name: 'myapi',
                    endpoint: "endpoint",
                    region: "region"
                },
            ],
            webSocket: "webSocket"
        },
    })

这是升级后的样子:

Amplify.configure({
        Auth: {
            mandatorySignIn: true,
            userPoolWebClientId: "userPoolWebClientId",
            region: "region",
            Cognito: {
                identityPoolId: "identityPoolId",
                userPoolClientId: "userPoolClientId",
                userPoolId: "userPoolId",
                loginWith: {
                    oauth: {
                        domain: domainName,
                        scopes: ['openid email profile aws.cognito.signin.user.admin'],
                        redirectSignIn: [publicUrl.origin],
                        redirectSignOut: [publicUrl.origin],
                        responseType: 'code',
                    },
                    username: 'true',
                },
            },
        },
        Storage: {
            S3: {
                bucket: _get(s3Config, 'Bucket'),
                region: _get(s3Config, 'Region'),
            },
        },
        API: {
            REST: {
                myapi: {
                    endpoint: "endpoint",
                    region: "region",
                },
            },
        },
    });

cognitoUserPoolsTokenProvider.setKeyValueStorage(new CookieStorage({
        domain: window.location.hostname,
        secure: true,
        path: '/',
        expires: 7,
    }));

将 aws-amplify 从 ^4.1.0 更新到 ^6.0.13,流程中断是机器中未自动同步的时间

reactjs aws-lambda amazon-cognito aws-amplify
1个回答
0
投票

如果它仍然有帮助,我遇到了同样的问题,并将其追溯到与 aws-sdk v2 => v3 重大更改相关的 amplify 中的错误。未解决的问题在这里:

https://github.com/aws-amplify/amplify-js/issues/13192

基本问题是 核心/src/clients/middleware/retry/defaultRetryDecider.ts#L19

const errorCode = parsedError?.code;

应该是

const errorCode = parsedError?.name;

code
更改为
name
是您可能遇到的aws sdk更改)

这会导致 API 调用重试,因为它没有检测到时钟错误。

希望他们能够快速修复,但同时我们正在构建流程中寻找手动补丁作为解决方法。

© www.soinside.com 2019 - 2024. All rights reserved.