首页 > 解决方案 > 使用 aws-amplify 时如何将 cookie 过期时间设置为 30 分钟?

问题描述

以下代码是放大身份验证的手动配置,我只想设置expirescookieStorage30 分钟而不是 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'
        }
    });

标签: javascriptreactjsaws-amplify

解决方案


好问题!

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

从文档:

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


推荐阅读