升级AWS-Amplify v6后手动改系统时钟致同步异常求助
AWS Amplify v6升级后时钟偏移同步异常问题
将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中,但请求仍无法正常对齐时间。
尝试过以下修复方式,但未生效:
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, }));
内容的提问来源于stack exchange,提问作者alex yeruhin
相关产品推荐
相关产品推荐

