Closed jewells07 closed 4 months ago
Hi @jewells07 - thanks for creating this ticket! Looking at your amplify/auth/post-confirmation/handler.ts
, it does not include an example of your call to Amplify.configure
, nor the generation of the API client. To help us better reproduce the issue, can you please include the complete code examples for the following?
amplify/auth/post-confirmation/handler.ts
- to see how you are configuring Amplify within the handler.amplify/auth/resource.ts
amplify/data/resource.ts
- I'd like to see how you are configuring the authorization rule to allow the postConfirmation resource.Lastly, I wanted to point out that unlike the docs you linked to above, it appears that you're missing the nested input
within the variables
input. In your case, your call to client.graphql
should be as follows:
const res = await client.graphql({
query: CreatingUserProfile,
variables: {
input: {
firstName: event.request.userAttributes.given_name,
lastName: event.request.userAttributes.family_name,
email: event.request.userAttributes.email,
birthdate: convertToISOStringExtended(event.request.userAttributes.birthdate),
owner: `${event.request.userAttributes.sub}::${event.userName}`,
},
},
});
it works now.
const client = generateClient<Schema>({
authMode: 'iam',
});
export const handler: PostConfirmationTriggerHandler = async (event) => {
try {
await client.graphql({
query: createUserProfile,
variables: {
input: {
firstName: event.request.userAttributes.given_name,
lastName: event.request.userAttributes.family_name,
email: event.request.userAttributes.email,
birthdate: convertToISOStringExtended(event.request.userAttributes.birthdate),
owner: `${event.request.userAttributes.sub}::${event.userName}`,
},
},
});
} catch (error: any) {
throw new Error(`Failed to create user profile: ${error.message}. full error ${error}`);
}
return event;
};
Before opening, please confirm:
JavaScript Framework
Vue
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
No response
Backend
Amplify Gen 2 (Preview)
Environment information
Describe the bug
I have "PostConfirmationTriggerHandler" on auth. When the user successfully creates (signup) it, it will trigger and create user profile data. So on PostConfirmationTriggerHandler, I am trying to call mutation to create a user profile; It gives me error 'Not Authorized to access CreatingUserProfile on type Mutation'. I have followed these steps. https://docs.amplify.aws/vue/build-a-backend/functions/examples/create-user-profile-record/, but with mutations
Expected behavior
It should authorized "iam" for mutation
Reproduction steps
In amplify/data/resource.ts
In amplify/auth/post-confirmation/handler.ts
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response