Skip to content

update reference auth with groups #8234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
"aws-sdk-ios",
"aws.cognito.signin.user.admin",
"aws",
"Authadmin",
"AWSAPI",
"AWSAPIGateway",
"AWSAPIPlugin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ export const auth = referenceAuth({
});
```

Additionally, you can also use the `groups` property to define groups created in the user pool. This is useful if you want to work with groups in your application and provide access to resources such as storage based on group membership.

```ts title="amplify/auth/resource.ts"
import { referenceAuth } from '@aws-amplify/backend';
import { getUser } from "../functions/get-user/resource";

export const auth = referenceAuth({
userPoolId: 'us-east-1_xxxx',
identityPoolId: 'us-east-1:b57b7c3b-9c95-43e4-9266-xxxx',
authRoleArn: 'arn:aws:iam::xxxx:role/amplify-xxxx-mai-amplifyAuthauthenticatedU-xxxx',
unauthRoleArn: 'arn:aws:iam::xxxx:role/amplify-xxxx-mai-amplifyAuthunauthenticate-xxxx',
userPoolClientId: 'xxxx',
groups: {
admin: "arn:aws:iam::xxxx:role/amplify-xxxx-mai-amplifyAuthadminGroupRole-xxxx",
},
});
```

In a team setting you may want to reference a different set of auth resources depending on the deployment context. For instance if you have a `staging` branch that should reuse resources from a separate "staging" environment compared to a `production` branch that should reuse resources from the separate "production" environment. In this case we recommend using environment variables.

```ts title="amplify/auth/resource.ts"
Expand Down