使用aws-amplify时如何将cookie的过期时间设置为30分钟?

时间:2018-12-05 18:38:24

标签: javascript reactjs aws-amplify

以下代码是对auth进行手动配置的功能,我只想将expires下的cookieStorage设置为30分钟而不是365天。

import Amplify from 'aws-amplify';

    Amplify.configure({
        Auth: {

            // REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
            identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',

            // REQUIRED - Amazon Cognito Region
            region: 'XX-XXXX-X',

            // OPTIONAL - Amazon Cognito Federated Identity Pool Region 
            // Required only if it's different from Amazon Cognito Region
            identityPoolRegion: 'XX-XXXX-X',

            // OPTIONAL - Amazon Cognito User Pool ID
            userPoolId: 'XX-XXXX-X_abcd1234',

            // OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
            userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',

            // OPTIONAL - Enforce user authentication prior to accessing AWS resources or not
            mandatorySignIn: false,

            // OPTIONAL - Configuration for cookie storage
            cookieStorage: {
            // REQUIRED - Cookie domain (only required if cookieStorage is provided)
                domain: '.yourdomain.com',
            // OPTIONAL - Cookie path
                path: '/',
            // OPTIONAL - Cookie expiration in days
                expires: 365,
            // OPTIONAL - Cookie secure flag
                secure: true
            },

            // OPTIONAL - customized storage object
            storage: new MyStorage(),

            // OPTIONAL - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
            authenticationFlowType: 'USER_PASSWORD_AUTH'
        }
    });

2 个答案:

答案 0 :(得分:0)

好问题!

我认为您只能将天设置为单位,而不能设置其他任何内容。

摘自文档:

The CookieStorage object receives a map (data) in its constructor that
may have these values:

data.domain Cookies domain (mandatory)
data.path Cookies path (default: '/') 
data.expires Cookie expiration (in days, default: 365)
data.secure Cookie secure flag (default: true)

https://github.com/aws-amplify/amplify-js/tree/master/packages/amazon-cognito-identity-js

答案 1 :(得分:0)

用一天的时间。 0.5将是12小时。 30分钟约为0.02。