Skip to content

Commit d410246

Browse files
authored
Merge pull request #179 from NHSDigital/feature/CCM-7248_auth-pages
CCM-7248: update header to point and redirect to /auth
2 parents d883e3e + b9364a4 commit d410246

File tree

10 files changed

+179
-11
lines changed

10 files changed

+179
-11
lines changed

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM node:20-alpine AS builder
2+
3+
# Install necessary packages for Puppeteer
4+
# Installs latest Chromium (100) package.
5+
RUN apk add --no-cache \
6+
chromium \
7+
ttf-freefont \
8+
udev
9+
10+
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
11+
12+
WORKDIR /app
13+
14+
COPY package*.json ./
15+
16+
RUN addgroup -S nonroot \
17+
&& adduser -S nonroot -G nonroot
18+
19+
# Set permissions to add files/folders to /app
20+
RUN chown -R nonroot:nonroot /app
21+
22+
# Switch to the non-root user
23+
USER nonroot
24+
25+
RUN npm ci --ignore-scripts
26+
27+
EXPOSE 3000
28+
29+
CMD ["npm", "run", "dev"]

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,36 @@
3737

3838
### Running the project locally
3939

40-
1) Convert the email HTML template into a JSON file that can be packaged with the email sending lambda.
40+
1. Convert the email HTML template into a JSON file that can be packaged with the email sending lambda.
4141

4242
```shell
4343
npm run generate-dependencies
4444
```
4545

46-
2) (Optional) If you want to test sending emails then you will need to set the following environment variables locally.
46+
2. (Optional) If you want to test sending emails then you will need to set the following environment variables locally.
4747

4848
```shell
4949
export ACCOUNT_ID=<aws_account_id>
5050
export NOTIFY_DOMAIN_NAME=<ses_verified_domain>
5151
```
5252

53-
3) To run an Amplify sandbox. To do this, authenticate with an AWS account that has Amplify enabled, then run:
53+
3. To run an Amplify sandbox. To do this, authenticate with an AWS account that has Amplify enabled, then run:
5454

5555
```shell
5656
npx ampx sandbox --profile <the name of the AWS config profile for the account you are authenticated with>
5757
```
5858

59-
4) Then in a separate terminal, run the app locally:
59+
4. Then in a separate terminal, run the app locally:
6060

6161
```shell
6262
npm run dev
6363
```
6464

65-
5) Open your browser and go to `localhost:3000` to view the app.
65+
5. Open your browser and go to `localhost:3000` to view the app.
66+
67+
### Running Team and IAM Web Auth projects locally
68+
69+
Read more in the [README.md](./local/README.md).
6670

6771
### Other commands
6872

@@ -91,3 +95,4 @@ module "amp_branch" {
9195
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/amp_branch?ref=v1.0.0"
9296
...
9397
}
98+
```

local/.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TEMPLATE_MANAGEMENT_DIR='your directory path to nhs-notify-web-template-management'
2+
IAM_WEBAUTH_DIR='your directory path to nhs-notify-web-iam'

local/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Experimental: Local setup for both templates-ui and iam-auth applications
2+
3+
This has only been tried on a mac.
4+
5+
If this local setup proves useful for others it would be great to move this `/local` directory to it's own GitHub repository.
6+
7+
## Description
8+
9+
A docker-compose setup to run multiple web applications locally and served to the same domain: `localhost`.
10+
11+
Two web applications have been configured `nhs-notify-web-templates-management` and `nhs-notify-iam-webauth` are both served through `ngix` which acts as a gateway.
12+
13+
- `nhs-notify-web-templates-management` is served to `http://localhost/templates`
14+
- `nhs-notify-iam-webauth` is served to `http://localhost/auth`
15+
16+
The `docker-compose` file is hooked up to local volume of the projects so any changes you make in your webapps will be ported across, you will need to refresh the web page to see the changes.
17+
18+
### Additional information
19+
20+
At first the application may take a few seconds to warm up. After the app has warmed up it's usually just as fast as running the application natively.
21+
22+
If you install a new `npm` package in either web application then you'll need to rebuild the docker images.
23+
24+
## Requirements
25+
26+
- local version of `nhs-notify-iam-webauth` project
27+
- docker-compose
28+
- If you're on windows you'll need to configure docker to work through WSL2 [here is a guide that might help](https://docs.docker.com/desktop/features/wsl/)
29+
30+
## Setup
31+
32+
### Setup Amplify sandboxes
33+
34+
Setup the Amplify sandboxes in a new terminal as explained in each web-apps [README.md](../README.md#running-the-project-locally)
35+
36+
### Configure project paths
37+
38+
You'll need to set the directory path location for each web application in the `.env` file or as environment variables.
39+
40+
For example:
41+
42+
```bash
43+
TEMPLATE_MANAGEMENT_DIR='~/projects/nhs-notify-web-template-management'
44+
IAM_WEBAUTH_DIR='~/projects/nhs-notify-iam-webauth'
45+
```
46+
47+
If you're using the `.env` file you might need to run `direnv allow`.
48+
49+
### Run
50+
51+
in the `/local/` directory run:
52+
53+
```bash
54+
docker-compose up
55+
```
56+
57+
First time running this it might take some time as `docker` downloads the base images and configures itself. After subsequent uses it will be much faster to start and stop.

local/docker-compose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
services:
2+
nginx:
3+
image: nginx:latest
4+
ports:
5+
- 80:80
6+
volumes:
7+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
8+
stdin_open: true
9+
tty: true
10+
depends_on:
11+
- templates
12+
- auth
13+
14+
templates:
15+
build:
16+
context: ${TEMPLATE_MANAGEMENT_DIR}
17+
dockerfile: Dockerfile
18+
ports:
19+
- 3000
20+
volumes:
21+
- ${TEMPLATE_MANAGEMENT_DIR}:/app
22+
- /app/node_modules
23+
24+
auth:
25+
build:
26+
context: ${IAM_WEBAUTH_DIR}
27+
dockerfile: Dockerfile
28+
ports:
29+
- 3000
30+
volumes:
31+
- ${IAM_WEBAUTH_DIR}:/app
32+
- /app/node_modules

local/nginx.conf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
events {
2+
worker_connections 1024;
3+
}
4+
5+
http {
6+
client_header_buffer_size 16k;
7+
8+
upstream auth {
9+
server auth:3000;
10+
}
11+
12+
upstream templates {
13+
server templates:3000;
14+
}
15+
16+
server {
17+
listen 80;
18+
19+
location /auth {
20+
proxy_pass http://auth/auth;
21+
proxy_set_header Host $host;
22+
proxy_set_header X-Real-IP $remote_addr;
23+
}
24+
25+
location /templates {
26+
proxy_pass http://templates/templates;
27+
proxy_set_header Host $host;
28+
proxy_set_header X-Real-IP $remote_addr;
29+
}
30+
}
31+
}

src/components/molecules/Header/Header.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ export function NHSNotifyHeader({ className, dataTestId }: HeaderType) {
5757
{/* I am currently testing the link wrapper, this will change later when we implement auth as the link will change based on auth state */}
5858
{process.env.NEXT_PUBLIC_DISABLE_CONTENT === 'true' ? null : (
5959
<div className='nhsuk-account__login' data-testid='login-link'>
60-
<Link className='nhsuk-account__login--link' href='/'>
61-
{content.components.headerComponent.links.logIn}
62-
</Link>
60+
<a
61+
className='nhsuk-account__login--link'
62+
href={content.components.headerComponent.links.logIn.href}
63+
>
64+
{content.components.headerComponent.links.logIn.text}
65+
</a>
6366
</div>
6467
)}
6568
</div>

src/content/content.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { TemplateType } from '@utils/enum';
44
const headerComponent = {
55
serviceName: 'Notify',
66
links: {
7-
logIn: 'Log in',
7+
logIn: {
8+
text: 'Log in',
9+
href: `/auth?redirect=${encodeURIComponent(
10+
`${getBasePath()}/create-and-submit-templates`
11+
)}`,
12+
},
813
logOut: 'Log out',
914
},
1015
};

tests/test-team/template-mgmt-component-tests/template-mgmt-common.steps.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export function assertLoginLink({ page, id, baseURL }: CommonStepsProps) {
4343

4444
await page.clickLoginLink();
4545

46-
await expect(page.page).toHaveURL(`${baseURL}/templates`);
46+
await expect(page.page).toHaveURL(
47+
`${baseURL}/auth?redirect=%2Ftemplates%2Fcreate-and-submit-templates`
48+
);
4749
});
4850
}
4951

tests/test-team/template-mgmt-component-tests/template-mgmt-start-page.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ test.describe('Start Page', () => {
5454
await startPage.navigateToStartPage();
5555
await startPage.clickLoginLink();
5656

57-
await expect(page).toHaveURL(`${baseURL}/templates`);
57+
await expect(page).toHaveURL(
58+
`${baseURL}/auth?redirect=%2Ftemplates%2Fcreate-and-submit-templates`
59+
);
5860

5961
expect(await page.locator('h1').textContent()).toBe('404');
6062
}

0 commit comments

Comments
 (0)