diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a24f7b2ebbb..b6574c0fc16 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -15,24 +15,24 @@ # The following paths involve server-side use cases, token/user session management. # Changes made to these paths requires additional reviews and approvals. -/packages/auth @haverchuck @cshfang @HuiSF @pranavosu -/packages/aws-amplify/src/adapter-core @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/adapterCore @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/singleton @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/utils/convert @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/utils/WordArray.ts @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/storage @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/utils/generateRandomString.ts @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/utils/globalHelpers @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/utils/urlSafeDecode.ts @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/awsClients/cognitoIdentity @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/clients/internal @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/Hub @haverchuck @cshfang @HuiSF @pranavosu -/packages/adapter-nextjs @haverchuck @cshfang @HuiSF @pranavosu -/packages/rtn-web-browser @haverchuck @cshfang @HuiSF @pranavosu -/packages/storage/src/providers/s3/apis/internal @haverchuck @cshfang @HuiSF @pranavosu -/packages/storage/src/providers/s3/apis/server @haverchuck @cshfang @HuiSF @pranavosu -/packages/api-rest/src/apis/server.ts @haverchuck @cshfang @HuiSF @pranavosu -/packages/api-rest/src/apis/common/internalPost.ts @haverchuck @cshfang @HuiSF @pranavosu -/packages/api-graphql/src/server @haverchuck @cshfang @HuiSF @pranavosu -/packages/api-graphql/src/internals/server @haverchuck @cshfang @HuiSF @pranavosu +/packages/auth @sktimalsina @cshfang @HuiSF @pranavosu +/packages/aws-amplify/src/adapter-core @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/adapterCore @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/singleton @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/utils/convert @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/utils/WordArray.ts @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/storage @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/utils/generateRandomString.ts @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/utils/globalHelpers @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/utils/urlSafeDecode.ts @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/awsClients/cognitoIdentity @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/clients/internal @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/Hub @sktimalsina @cshfang @HuiSF @pranavosu +/packages/adapter-nextjs @sktimalsina @cshfang @HuiSF @pranavosu +/packages/rtn-web-browser @sktimalsina @cshfang @HuiSF @pranavosu +/packages/storage/src/providers/s3/apis/internal @sktimalsina @cshfang @HuiSF @pranavosu +/packages/storage/src/providers/s3/apis/server @sktimalsina @cshfang @HuiSF @pranavosu +/packages/api-rest/src/apis/server.ts @sktimalsina @cshfang @HuiSF @pranavosu +/packages/api-rest/src/apis/common/internalPost.ts @sktimalsina @cshfang @HuiSF @pranavosu +/packages/api-graphql/src/server @sktimalsina @cshfang @HuiSF @pranavosu +/packages/api-graphql/src/internals/server @sktimalsina @cshfang @HuiSF @pranavosu diff --git a/.github/integ-config/integ-all.yml b/.github/integ-config/integ-all.yml index 3c37683608b..4759997ee29 100644 --- a/.github/integ-config/integ-all.yml +++ b/.github/integ-config/integ-all.yml @@ -875,14 +875,24 @@ tests: # spec: duplicate-packages # browser: *minimal_browser_list - # SSR context isolation - - test_name: integ_ssr_context_isolation - desc: 'SSR Context Isolation' + # Next.js use cases + - test_name: integ_next-use-cases-14 + desc: 'Next.js use cases tests with v14' framework: next category: ssr-adapter - sample_name: ssr-context-isolation - spec: ssr-context-isolation - yarn_script: ci:ssr-context-isolation + sample_name: next-use-cases-14 + spec: next-use-cases + yarn_script: ci:next-use-cases-test + yarn_script_args: 14 + browser: [chrome] + - test_name: integ_next-use-cases-15 + desc: 'Next.js use cases tests with v15' + framework: next + category: ssr-adapter + sample_name: next-use-cases-15 + spec: next-use-cases + yarn_script: ci:next-use-cases-test + yarn_script_args: 15 browser: [chrome] - test_name: integ_next_mfa_req_email desc: 'mfa required with email sign in attribute' @@ -890,7 +900,7 @@ tests: category: auth sample_name: [mfa] spec: mfa-req-email - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: mfa-req-email - test_name: integ_next_mfa_req_phone @@ -899,7 +909,7 @@ tests: category: auth sample_name: [mfa] spec: mfa-req-phone - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: mfa-req-phone - test_name: integ_next_mfa_opt_email @@ -908,7 +918,7 @@ tests: category: auth sample_name: [mfa] spec: mfa-opt-email - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: mfa-opt-email - test_name: integ_next_mfa_opt_phone @@ -917,7 +927,7 @@ tests: category: auth sample_name: [mfa] spec: mfa-opt-phone - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: mfa-opt-phone - test_name: integ_next_mfa_setup @@ -926,7 +936,7 @@ tests: category: auth sample_name: [mfa] spec: mfa-setup - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: mfa-setup - test_name: integ_next_passwordless_auto_sign_in @@ -935,8 +945,7 @@ tests: category: auth sample_name: [mfa] spec: passwordless/auto-sign-in - # browser: *minimal_browser_list - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: pwl-autosignin - test_name: integ_next_passwordless_first_factor_selection @@ -945,8 +954,7 @@ tests: category: auth sample_name: [mfa] spec: passwordless/first-factor-selection - # browser: *minimal_browser_list - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: pwl-ffselect - test_name: integ_next_passwordless_preferred_challenge @@ -955,8 +963,7 @@ tests: category: auth sample_name: [mfa] spec: passwordless/preferred-challenge - # browser: *minimal_browser_list - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: pwl-prefchal - test_name: integ_next_passwordless_sign_up @@ -965,8 +972,7 @@ tests: category: auth sample_name: [mfa] spec: passwordless/sign-up - # browser: *minimal_browser_list - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: pwl-signup - test_name: integ_next_passwordless_misc @@ -975,8 +981,7 @@ tests: category: auth sample_name: [mfa] spec: passwordless/miscellaneous - # browser: *minimal_browser_list - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: pwl-misc - test_name: integ_next_passwordless_webauthn diff --git a/.github/workflows/callable-e2e-test.yml b/.github/workflows/callable-e2e-test.yml index ee02150baa3..a0bfd77d22f 100644 --- a/.github/workflows/callable-e2e-test.yml +++ b/.github/workflows/callable-e2e-test.yml @@ -37,6 +37,9 @@ on: yarn_script: required: false type: string + yarn_script_args: + required: false + type: number env: required: false type: string @@ -124,6 +127,7 @@ jobs: E2E_RETRY_COUNT: ${{ inputs.retry_count }} E2E_TEST_NAME: ${{ inputs.test_name }} E2E_YARN_SCRIPT: ${{ inputs.yarn_script }} + E2E_YARN_SCRIPT_ARGS: ${{ inputs.yarn_script_args }} E2E_ENV: ${{ inputs.env }} run: | if [ -z "$E2E_YARN_SCRIPT" ]; then @@ -141,7 +145,7 @@ jobs: $E2E_YARN_SCRIPT \ -n $E2E_RETRY_COUNT else - yarn "$E2E_YARN_SCRIPT" + yarn "$E2E_YARN_SCRIPT" "$E2E_YARN_SCRIPT_ARGS" fi - name: Upload artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 https://github.com/actions/upload-artifact/commit/0b7f8abb1508181956e8e162db84b466c27e18ce diff --git a/.github/workflows/callable-e2e-tests.yml b/.github/workflows/callable-e2e-tests.yml index 2b7604b1215..bdb174e32a7 100644 --- a/.github/workflows/callable-e2e-tests.yml +++ b/.github/workflows/callable-e2e-tests.yml @@ -44,6 +44,7 @@ jobs: timeout_minutes: ${{ matrix.integ-config.timeout_minutes || 35 }} retry_count: ${{ matrix.integ-config.retry_count || 3 }} yarn_script: ${{ matrix.integ-config.yarn_script || '' }} + yarn_script_args: ${{ matrix.integ-config.yarn_script_args || 15 }} env: ${{ matrix.integ-config.env && toJSON(matrix.integ-config.env) || '{}' }} # e2e-test-runner-headless: diff --git a/packages/adapter-nextjs/__tests__/createServerRunner.test.ts b/packages/adapter-nextjs/__tests__/createServerRunner.test.ts index 5dbaa9e0071..3509a4b49c3 100644 --- a/packages/adapter-nextjs/__tests__/createServerRunner.test.ts +++ b/packages/adapter-nextjs/__tests__/createServerRunner.test.ts @@ -124,7 +124,7 @@ describe('createServerRunner', () => { }); describe('when nextServerContext is not null', () => { - it('should create auth providers with cookie storage adapter', () => { + it('should create auth providers with cookie storage adapter', async () => { const operation = jest.fn(); const mockCookieStorageAdapter = { get: jest.fn(), @@ -147,7 +147,7 @@ describe('createServerRunner', () => { const { runWithAmplifyServerContext } = createServerRunner({ config: mockAmplifyConfig, }); - runWithAmplifyServerContext({ + await runWithAmplifyServerContext({ operation, nextServerContext: mockNextServerContext as unknown as NextServer.Context, diff --git a/packages/adapter-nextjs/__tests__/utils/createCookieStorageAdapterFromNextServerContext.test.ts b/packages/adapter-nextjs/__tests__/utils/createCookieStorageAdapterFromNextServerContext.test.ts index a42ec085e9c..c81383ea804 100644 --- a/packages/adapter-nextjs/__tests__/utils/createCookieStorageAdapterFromNextServerContext.test.ts +++ b/packages/adapter-nextjs/__tests__/utils/createCookieStorageAdapterFromNextServerContext.test.ts @@ -7,6 +7,7 @@ import { Socket } from 'net'; import { enableFetchMocks } from 'jest-fetch-mock'; import { NextRequest, NextResponse } from 'next/server.js'; import { cookies } from 'next/headers.js'; +import { CookieStorage } from 'aws-amplify/adapter-core'; import { DATE_IN_THE_PAST, @@ -46,29 +47,32 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { describe('cookieStorageAdapter created from NextRequest and NextResponse', () => { const request = new NextRequest(new URL('https://example.com')); const response = NextResponse.next(); - - jest.spyOn(request, 'cookies', 'get').mockImplementation( - () => - ({ - get: mockGetFunc, - getAll: mockGetAllFunc, - }) as any, - ); - - jest.spyOn(response, 'cookies', 'get').mockImplementation(() => ({ - set: mockSetFunc, - delete: mockDeleteFunc, - get: jest.fn(), - getAll: jest.fn(), - has: jest.fn(), - })); - const mockContext = { request, response, } as any; + let result: CookieStorage.Adapter; + + beforeAll(async () => { + jest.spyOn(request, 'cookies', 'get').mockImplementation( + () => + ({ + get: mockGetFunc, + getAll: mockGetAllFunc, + }) as any, + ); - const result = createCookieStorageAdapterFromNextServerContext(mockContext); + jest.spyOn(response, 'cookies', 'get').mockImplementation(() => ({ + set: mockSetFunc, + delete: mockDeleteFunc, + get: jest.fn(), + getAll: jest.fn(), + has: jest.fn(), + })); + + result = + await createCookieStorageAdapterFromNextServerContext(mockContext); + }); it('gets cookie by calling `get` method of the underlying cookie store', () => { result.get(mockKey); @@ -121,26 +125,32 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { describe('cookieStorageAdapter created from NextRequest and Response', () => { const request = new NextRequest(new URL('https://example.com')); const response = new Response(); - - jest.spyOn(request, 'cookies', 'get').mockImplementation( - () => - ({ - get: mockGetFunc, - getAll: mockGetAllFunc, - }) as any, - ); - jest.spyOn(response, 'headers', 'get').mockImplementation( - () => - ({ - append: mockAppend, - }) as any, - ); - const mockContext = { request, response, } as any; + let result: CookieStorage.Adapter; + + beforeAll(async () => { + jest.spyOn(request, 'cookies', 'get').mockImplementation( + () => + ({ + get: mockGetFunc, + getAll: mockGetAllFunc, + }) as any, + ); + jest.spyOn(response, 'headers', 'get').mockImplementation( + () => + ({ + append: mockAppend, + }) as any, + ); + + result = + await createCookieStorageAdapterFromNextServerContext(mockContext); + }); + const mockSerializeOptions = { domain: 'example.com', expires: new Date('2023-08-22'), @@ -150,8 +160,6 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { path: '/a-path', }; - const result = createCookieStorageAdapterFromNextServerContext(mockContext); - it('gets cookie by calling `get` method of the underlying cookie store', () => { result.get(mockKey); expect(mockGetFunc).toHaveBeenCalledWith(mockKey); @@ -233,9 +241,15 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { }); describe('cookieStorageAdapter created from Next cookies function', () => { - mockNextCookiesFunc.mockReturnValueOnce(mockNextCookiesFuncReturn); + let result: CookieStorage.Adapter; + + beforeAll(async () => { + mockNextCookiesFunc.mockReturnValueOnce(mockNextCookiesFuncReturn); - const result = createCookieStorageAdapterFromNextServerContext({ cookies }); + result = await createCookieStorageAdapterFromNextServerContext({ + cookies, + }); + }); it('gets cookie by calling `get` method of the underlying cookie store', () => { result.get(mockKey); @@ -286,7 +300,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { }); describe('cookieStorageAdapter created from IncomingMessage and ServerResponse as the Pages Router context', () => { - it('operates with the underlying cookie store', () => { + it('operates with the underlying cookie store', async () => { const mockCookies = { key1: 'value1', key2: 'value2', @@ -302,7 +316,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { }, }); - const result = createCookieStorageAdapterFromNextServerContext({ + const result = await createCookieStorageAdapterFromNextServerContext({ request: request as any, response, }); @@ -341,7 +355,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { ]); }); - it('operates with the underlying cookie store with encoded cookie names', () => { + it('operates with the underlying cookie store with encoded cookie names', async () => { // these the auth keys generated by Amplify const encodedCookieName1 = encodeURIComponent('test@email.com.idToken'); const encodedCookieName2 = encodeURIComponent( @@ -364,7 +378,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { }, }); - const result = createCookieStorageAdapterFromNextServerContext({ + const result = await createCookieStorageAdapterFromNextServerContext({ request: request as any, response, }); @@ -413,7 +427,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { ]); }); - it('does not add duplicate cookies when the cookies are defined in the response Set-Cookie headers', () => { + it('does not add duplicate cookies when the cookies are defined in the response Set-Cookie headers', async () => { const mockExistingSetCookieValues = [ 'CognitoIdentityServiceProvider.1234.accessToken=1234;Path=/', 'CognitoIdentityServiceProvider.1234.refreshToken=1234;Path=/', @@ -433,7 +447,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { getHeaderSpy.mockReturnValue(mockExistingSetCookieValues); - const result = createCookieStorageAdapterFromNextServerContext({ + const result = await createCookieStorageAdapterFromNextServerContext({ request: request as any, response, }); @@ -455,6 +469,6 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { request: undefined, response: new ServerResponse({} as any), } as any), - ).toThrow(); + ).rejects.toThrow(); }); }); diff --git a/packages/adapter-nextjs/package.json b/packages/adapter-nextjs/package.json index e56ca3d05c0..8c00508ecfd 100644 --- a/packages/adapter-nextjs/package.json +++ b/packages/adapter-nextjs/package.json @@ -5,7 +5,7 @@ "description": "The adapter for the supporting of using Amplify APIs in Next.js.", "peerDependencies": { "aws-amplify": "^6.0.7", - "next": ">=13.5.0 <15.0.0" + "next": ">=13.5.0 <16.0.0" }, "dependencies": { "aws-jwt-verify": "^4.0.1", diff --git a/packages/adapter-nextjs/src/utils/createCookieStorageAdapterFromNextServerContext.ts b/packages/adapter-nextjs/src/utils/createCookieStorageAdapterFromNextServerContext.ts index e3f99cbf96c..c36776d3ad1 100644 --- a/packages/adapter-nextjs/src/utils/createCookieStorageAdapterFromNextServerContext.ts +++ b/packages/adapter-nextjs/src/utils/createCookieStorageAdapterFromNextServerContext.ts @@ -11,9 +11,9 @@ import { NextServer } from '../types'; export const DATE_IN_THE_PAST = new Date(0); -export const createCookieStorageAdapterFromNextServerContext = ( +export const createCookieStorageAdapterFromNextServerContext = async ( context: NextServer.Context, -): CookieStorage.Adapter => { +): Promise => { const { request: req, response: res } = context as Partial; @@ -110,10 +110,10 @@ const createCookieStorageAdapterFromNextRequestAndHttpResponse = ( }; }; -const createCookieStorageAdapterFromNextCookies = ( +const createCookieStorageAdapterFromNextCookies = async ( cookies: NextServer.ServerComponentContext['cookies'], -): CookieStorage.Adapter => { - const cookieStore = cookies(); +): Promise => { + const cookieStore = await cookies(); // When Next cookies() is called in a server component, it returns a readonly // cookie store. Hence calling set and delete throws an error. However, diff --git a/packages/adapter-nextjs/src/utils/createRunWithAmplifyServerContext.ts b/packages/adapter-nextjs/src/utils/createRunWithAmplifyServerContext.ts index 3d20f19cd67..497f56f33dc 100644 --- a/packages/adapter-nextjs/src/utils/createRunWithAmplifyServerContext.ts +++ b/packages/adapter-nextjs/src/utils/createRunWithAmplifyServerContext.ts @@ -32,7 +32,7 @@ export const createRunWithAmplifyServerContext = ({ nextServerContext === null ? sharedInMemoryStorage : createKeyValueStorageFromCookieStorageAdapter( - createCookieStorageAdapterFromNextServerContext( + await createCookieStorageAdapterFromNextServerContext( nextServerContext, ), createTokenValidator({ diff --git a/packages/api-graphql/src/internals/v6.ts b/packages/api-graphql/src/internals/v6.ts index c5d362908c8..553707be092 100644 --- a/packages/api-graphql/src/internals/v6.ts +++ b/packages/api-graphql/src/internals/v6.ts @@ -4,6 +4,7 @@ import { CustomHeaders } from '@aws-amplify/data-schema/runtime'; import { GraphQLAPI } from '../GraphQLAPI'; import { + GraphQLOptions, GraphQLOptionsV6, GraphQLResponseV6, V6Client, @@ -113,10 +114,11 @@ export function graphql< * Neither of these can actually be validated at runtime. Hence, we don't perform * any validation or type-guarding here. */ + const result = GraphQLAPI.graphql( // TODO: move V6Client back into this package? internals.amplify as any, - options, + options as GraphQLOptions, headers, ); diff --git a/packages/api-graphql/src/types/index.ts b/packages/api-graphql/src/types/index.ts index 0ecac34369a..d642fff3bd1 100644 --- a/packages/api-graphql/src/types/index.ts +++ b/packages/api-graphql/src/types/index.ts @@ -212,7 +212,7 @@ export type GraphQLOperation = Source | string; export interface GraphQLOptionsV6< FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string, -> { +> extends Record { query: TYPED_GQL_STRING | DocumentNode; variables?: GraphQLVariablesV6; authMode?: GraphQLAuthMode; diff --git a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts index ea2582a6d47..ae62578be5e 100644 --- a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts +++ b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts @@ -109,7 +109,6 @@ export async function confirmSignIn( }); if (AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ username, ...AuthenticationResult, @@ -121,6 +120,7 @@ export async function confirmSignIn( }), signInDetails, }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts index 348c60870ae..5911266475b 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts @@ -84,8 +84,6 @@ export async function signInWithCustomAuth( signInDetails, }); if (AuthenticationResult) { - cleanActiveSignInState(); - await cacheCognitoTokens({ username: activeUsername, ...AuthenticationResult, @@ -97,6 +95,7 @@ export async function signInWithCustomAuth( }), signInDetails, }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts index 4cff40e7cd7..aa92e3e6012 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts @@ -91,7 +91,6 @@ export async function signInWithSRP( signInDetails, }); if (AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ username: activeUsername, ...AuthenticationResult, @@ -103,6 +102,7 @@ export async function signInWithSRP( }), signInDetails, }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts index 9ac1223a105..94165046864 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts @@ -100,7 +100,6 @@ export async function signInWithUserAuth( }); if (response.AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ username: activeUsername, ...response.AuthenticationResult, @@ -112,6 +111,8 @@ export async function signInWithUserAuth( }), signInDetails, }); + cleanActiveSignInState(); + await dispatchSignedInHubEvent(); resetAutoSignIn(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts index 0cd3acd88d3..8027af90c71 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts @@ -86,7 +86,6 @@ export async function signInWithUserPassword( signInDetails, }); if (AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ ...AuthenticationResult, username: activeUsername, @@ -98,6 +97,7 @@ export async function signInWithUserPassword( }), signInDetails, }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); diff --git a/packages/datastore/src/types.ts b/packages/datastore/src/types.ts index abc92322cc7..a36cad59ca1 100644 --- a/packages/datastore/src/types.ts +++ b/packages/datastore/src/types.ts @@ -506,6 +506,10 @@ export type TypeConstructorMap = Record< export declare const __identifierBrand__: unique symbol; export type IdentifierBrand = T & { [__identifierBrand__]: K }; +interface GenericIdentifier { + field: any; +} + // datastore generates a uuid for you export type ManagedIdentifier = IdentifierBrand< { field: F extends string ? F : never; type: T }, @@ -548,7 +552,9 @@ export type IdentifierFields< infer B > ? B[number] // B[number] - : MetadataOrDefault['identifier']['field']) & + : MetadataOrDefault['identifier'] extends GenericIdentifier + ? MetadataOrDefault['identifier']['field'] + : unknown) & string; export type IdentifierFieldsForInit< @@ -710,7 +716,9 @@ export type IdentifierFieldValue< ? MetadataOrDefault['identifier']['fields'] extends [any] ? T[MetadataOrDefault['identifier']['fields'][0]] : never - : T[MetadataOrDefault['identifier']['field']]; + : MetadataOrDefault['identifier'] extends GenericIdentifier + ? T[MetadataOrDefault['identifier']['field']] + : unknown; export type IdentifierFieldOrIdentifierObject< T extends PersistentModel, diff --git a/yarn.lock b/yarn.lock index d24a3ecba52..d86004d054c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11926,9 +11926,9 @@ mute-stream@^1.0.0, mute-stream@~1.0.0: integrity sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA== nanoid@^3.3.6: - version "3.3.7" - resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8" - integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g== + version "3.3.8" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.8.tgz#b1be3030bee36aaff18bacb375e5cce521684baf" + integrity sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w== nanospinner@^1.1.0: version "1.1.0"