Skip to content

Commit

Permalink
chore(aws-amplify): export necessary utilities to support server-side…
Browse files Browse the repository at this point in the history
… auth
  • Loading branch information
HuiSF committed Oct 1, 2024
1 parent 95e5987 commit ec3f072
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/aws-amplify/__tests__/exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ describe('aws-amplify Exports', () => {
it('should only export expected symbols from the Cognito provider', () => {
expect(Object.keys(authCognitoExports).sort()).toEqual(
[
'AUTH_KEY_PREFIX',
'createKeysForAuthStorage',
'signUp',
'resetPassword',
'confirmResetPassword',
Expand All @@ -200,7 +202,10 @@ describe('aws-amplify Exports', () => {
'setUpTOTP',
'updateUserAttributes',
'updateUserAttribute',
'generateCodeVerifier',
'generateState',
'getCurrentUser',
'getRedirectUrl',
'confirmUserAttribute',
'signInWithRedirect',
'fetchUserAttributes',
Expand All @@ -220,6 +225,7 @@ describe('aws-amplify Exports', () => {
'DefaultTokenStore',
'refreshAuthTokens',
'refreshAuthTokensWithoutDedupe',
'validateState',
].sort(),
);
});
Expand Down
4 changes: 4 additions & 0 deletions packages/aws-amplify/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module.exports = {
statements: 91,
},
},
coveragePathIgnorePatterns: [
'src/adapter-core/index.ts',
'src/utils/index.ts',
],
moduleNameMapper: {
uuid: require.resolve('uuid'),
},
Expand Down
4 changes: 4 additions & 0 deletions packages/aws-amplify/src/adapter-core/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

export const DEFAULT_COOKIE_EXPIRY = 365 * 24 * 60 * 60 * 1000; // 1 year in milliseconds
9 changes: 9 additions & 0 deletions packages/aws-amplify/src/adapter-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ export {
AmplifyServer,
CookieStorage,
} from '@aws-amplify/core/internals/adapter-core';
export {
generateState,
getRedirectUrl,
generateCodeVerifier,
validateState,
createKeysForAuthStorage,
AUTH_KEY_PREFIX,
} from '@aws-amplify/auth/cognito';
export { DEFAULT_COOKIE_EXPIRY } from './constants';
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {
KeyValueStorageMethodValidator,
} from '@aws-amplify/core/internals/adapter-core';

import { DEFAULT_COOKIE_EXPIRY } from '../constants';

export const defaultSetCookieOptions: CookieStorage.SetCookieOptions = {
// TODO: allow configure with a public interface
sameSite: 'lax',
secure: true,
path: '/',
};
const ONE_YEAR_IN_MS = 365 * 24 * 60 * 60 * 1000;

/**
* Creates a Key Value storage interface using the `cookieStorageAdapter` as the
Expand All @@ -40,7 +41,7 @@ export const createKeyValueStorageFromCookieStorageAdapter = (
// TODO(HuiSF): follow up the default CookieSerializeOptions values
cookieStorageAdapter.set(key, value, {
...defaultSetCookieOptions,
expires: new Date(Date.now() + ONE_YEAR_IN_MS),
expires: new Date(Date.now() + DEFAULT_COOKIE_EXPIRY),
...overrideCookieAttributes,
});

Expand Down

0 comments on commit ec3f072

Please sign in to comment.