You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a type definition mismatch between the runtime implementation and TypeScript types for AuthMode in Amplify Generation 2. The runtime expects 'userPools' (plural) as a valid auth mode, but the TypeScript type definition only includes 'userPool' (singular). This leads to TypeScript errors and potential runtime authentication issues.
Current Behavior
TypeScript type AuthMode includes 'userPool' (singular)
This causes type errors when trying to use the correct runtime value
When using 'userPool' (as suggested by types), results in authentication errors
Error Details
When attempting to create an order with userPool (as suggested by types):
Error: NoValidAuthTokens: NofederatedjwtatheaderBasedAuth(webpack-internal:///(action-browser)/./node_modules/@aws-amplify/api-graphql/dist/esm/internals/graphqlAuth.mjs:49:23)atprocess.processTicksAndRejections(node:internal/process/task_queues:95:5)atasyncGraphQLAPIClass._graphql(webpack-internal:///(action-browser)/./node_modules/@aws-amplify/api-graphql/dist/esm/internals/InternalGraphQLAPI.mjs:150:29)atasynceval(webpack-internal:///(action-browser)/./node_modules/@aws-amplify/data-schema/dist/esm/runtime/internals/operations/get.mjs:47:42)Recovery Suggestion: "If you intended to make an authenticated API request, review if the current user is signed in."
Expected Behavior
The TypeScript type definition should match the runtime implementation by including 'userPools' as a valid value for AuthMode, preventing both type errors and runtime authentication issues.
Reproduction Steps
Create a new Amplify Gen2 project
Try to use userPools as the auth mode:
constorder=awaitclient.models.Order.create(orderData,{authMode: 'userPools',// Type error hereauthToken: token});
Observe the TypeScript error:
Type '"userPools"' is not assignable to type 'AuthMode | undefined'.
This type definition enforces using 'userPool' (singular), but the runtime implementation requires using 'userPools' (plural). When we use the working runtime value 'userPools', TypeScript shows a compilation error because it's not included in the AuthMode type.
This leads to a situation where using the correct runtime value ('userPools') works at runtime but fails TypeScript compilation, forcing developers to use type assertions as a workaround.
Impact
This type mismatch:
Forces developers to use type assertions
Creates confusion about the correct value to use
Reduces type safety by requiring workarounds
Can lead to runtime authentication failures when following the type definitions
Wastes development time debugging what appears to be an authentication issue but is actually a type definition mismatch
Reproduction steps
Reproduction Steps
Create a new Amplify Gen2 project
Try to use userPool as the auth mode within an NextJS action
//amplifyServerUtils.tsimport{createServerRunner}from'@aws-amplify/adapter-nextjs';importconfigfrom'@/amplify_outputs.json';import{cookies}from'next/headers';import{getCurrentUser,fetchUserAttributes,fetchAuthSession}from'aws-amplify/auth/server';import{AuthError,AuthUser}from'aws-amplify/auth';exportconst{ runWithAmplifyServerContext }=createServerRunner({
config,});exportinterfaceAuthResult{user: AuthUser|null;isAuthenticated: boolean;token?: string;}exportasyncfunctiongetServerSideUser(): Promise<AuthResult>{try{constresult=awaitrunWithAmplifyServerContext({nextServerContext: { cookies },operation: async(contextSpec)=>{constuser=awaitgetCurrentUser(contextSpec);constsession=awaitfetchAuthSession(contextSpec);consttoken=session.tokens?.idToken?.toString();return{ user, token };},});return{user: result?.user??null,isAuthenticated: true,token: result?.token,};}catch(error){if(errorinstanceofAuthError){return{user: null,isAuthenticated: false,token: undefined,};}console.error('Unexpected error in getServerSideUser:',error);return{user: null,isAuthenticated: false,token: undefined,};}}// actions.ts'use server';exportasyncfunctionsubmitOrder(orderData: OrderFormData){try{const{ user, token }=awaitgetServerSideUser();constorder=awaitclient.models.Order.create(orderData,{authMode: 'userPools',// Type error: not assignable to type 'AuthMode'authToken: token});}catch(error){console.error('Error:',error);}}
The text was updated successfully, but these errors were encountered:
Environment information
Describe the bug
AuthMode Type Definition Mismatch in Amplify Gen2
Description
There is a type definition mismatch between the runtime implementation and TypeScript types for
AuthMode
in Amplify Generation 2. The runtime expects'userPools'
(plural) as a valid auth mode, but the TypeScript type definition only includes'userPool'
(singular). This leads to TypeScript errors and potential runtime authentication issues.Current Behavior
AuthMode
includes'userPool'
(singular)'userPools'
(plural)'userPool'
(as suggested by types), results in authentication errorsError Details
When attempting to create an order with
userPool
(as suggested by types):Expected Behavior
The TypeScript type definition should match the runtime implementation by including
'userPools'
as a valid value forAuthMode
, preventing both type errors and runtime authentication issues.Reproduction Steps
userPools
as the auth mode:'userPool'
as suggested by types, observe the runtime error as well as the [docs]:(https://docs.amplify.aws/react/build-a-backend/data/customize-authz/per-user-per-owner-data-access/)Current Workaround
Currently, developers need to use type assertions to work around this issue:
Additional Context
The
AuthMode
type is currently defined as:This type definition enforces using 'userPool' (singular), but the runtime implementation requires using 'userPools' (plural). When we use the working runtime value 'userPools', TypeScript shows a compilation error because it's not included in the AuthMode type.
This leads to a situation where using the correct runtime value ('userPools') works at runtime but fails TypeScript compilation, forcing developers to use type assertions as a workaround.
Impact
This type mismatch:
Reproduction steps
Reproduction Steps
userPool
as the auth mode within an NextJS actionThe text was updated successfully, but these errors were encountered: