Skip to content

Commit

Permalink
Merge pull request #140 from NHSDigital/feature/CCM-8032_auth-terrafo…
Browse files Browse the repository at this point in the history
…rm-sandbox

CCM-8032: Use terraform sandbox
  • Loading branch information
chris-elliott-nhsd authored Jan 10, 2025
2 parents d9db458 + 2deb631 commit ae33910
Show file tree
Hide file tree
Showing 21 changed files with 433 additions and 8,614 deletions.
4 changes: 0 additions & 4 deletions .env.template

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ amplifyconfiguration*
.next
.env
.idea

sandbox_tf_outputs.json
sandbox_cognito_auth_token.json
56 changes: 26 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,41 @@ Read more about the technical design at [REFCOM-2024-007: WebUI User Auth](https
npm install
```

### Setup .env
### Creating a backend sandbox

copy and rename `.env.template` to `.env`
To create a backend sandbox intended for use with local development, run the command

#### USER_POOL_ID (optional)
```shell
npm run create-backend-sandbox environment-name
```

1. Log into the `nhs-notify-iam-dev` AWS account
2. Load AWS Cognito
3. Open `nhs-notify-main-app` Cognito user pool
4. Grab `User pool ID` value
substituting your environment name in as appropriate.

#### USER_POOL_CLIENT_ID (optional)
This command will also generate an amplify_outputs file in the root of the repository that will be used when running the app locally.

1. Log into the `nhs-notify-iam-dev` AWS account
2. Load AWS Cognito
3. Open `nhs-notify-main-app` Cognito user pool
4. Load `App integration` tab
1. Found (at the bottom of the page)
5. Grab `Client ID` value
To destroy the sandbox when it is no longer needed, run the command

#### USE_LOCAL_AUTH

```bash
true/false
```shell
npm run destroy-backend-sandbox environment-name
```

When `true` a new Cognito instance will be created within the Amplify sandbox. You'll need to manually add users.
### Connecting to an existing Cognito instance

You can point the app at any existing Cognito instance, not necessarily one you have created, by updating the user_pool_id and user_pool_client_id values in the amplify_outputs file.

### Setup a user in Cognito

In order to use a new Cognito user pool, you can run the sandbox auth script with your chosen email and password:

```bash
./scripts/sandbox_auth.sh email password
```

You can also manually create a user in that user pool:

1. Log into the `nhs-notify-iam-dev` AWS account
2. Load AWS Cognito
3. Open `nhs-notify-main-app` Cognito user pool
3. Open the relevant Cognito user pool
4. Select `Create user`
5. Enter details
1. Use your .nhs email address
Expand All @@ -82,17 +84,11 @@ When `true` a new Cognito instance will be created within the Amplify sandbox. Y

## Running project locally

1. To run an Amplify sandbox. To do this, authenticate with the AWS account `nhs-notify-iam-dev` then run:
Having created your backend sandbox or otherwise set up your amplify_outputs file, you can start the app locally by running

```bash
npx ampx sandbox --profile <your AWS profile for nhs-notify-iam-dev account>
```

2. Then in a separate terminal, run the app locally:

```bash
npm run dev
```
```bash
npm run dev
```

### Running WebAuth and Templates projects locally

Expand Down
20 changes: 20 additions & 0 deletions amplify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 1
backend:
phases:
build:
commands:
- npm ci --cache .npm --prefer-offline
- npm run generate-outputs env
frontend:
phases:
build:
commands:
- npm run build
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- .npm/**/*
- node_modules/**/*
20 changes: 0 additions & 20 deletions amplify/auth/resource.ts

This file was deleted.

9 changes: 0 additions & 9 deletions amplify/backend.ts

This file was deleted.

Loading

0 comments on commit ae33910

Please sign in to comment.