Skip to content

Commit

Permalink
Merge pull request #39 from erland-syafiq/VTMUNC-login
Browse files Browse the repository at this point in the history
Added environment variables to deployment
  • Loading branch information
erland-syafiq authored Jun 20, 2024
2 parents bbda342 + 68647f2 commit adfcf88
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ jobs:
run: docker pull vtmunc/site:latest
- name: Remove old containers
run: docker rm -f vtmunc || true
- name: Clean earlier .env
run: rm .env || true
- name: Create environment variables
run: echo ${{ secrets.ENV_FILE }} > .env
- name: Run container
run: docker run -p 3000:3000 -d --name vtmunc vtmunc/site
run: docker run -p 3000:3000 -d --name vtmunc --env_file .env vtmunc/site
- name: Removing environment variabe
run: rm .env || true
- name: Clean up (Removes old containers)
run: docker system prune -f
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The VTMUNC website is hosted on an Amazon EC2 instance, which serves as the core
## Table Of Contents:

- [🚀 Set Up](#-set-up)
- [⚙️ Environment Variables File](docs/env-file.md)
- [⚙️ Environment Variables](docs/env-file.md)
- [📂 Project Overview](docs/project-overview.md)
- [📙 Site Overview](docs/site-overview.md)
- [🎨 Style Guide](docs/style-guide.md)
Expand Down
4 changes: 2 additions & 2 deletions docs/assets/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ AWS_DYNAMODB_ACCESS_KEY_ID=<access key>
AWS_DYNAMODB_SECRET_ACCESS_KEY=<secret key>
AWS_DEFAULT_REGION=<default region e.g: us-east-1>
BACKEND_URL=<backend url e.g: localhost:3000>
USERNAME=<correct user email>
PASSWORD=<correct user password>
ADMIN_USERNAME=<correct user email>
ADMIN_PASSWORD=<correct user password>
JWT_SECRET=<secret key>
6 changes: 3 additions & 3 deletions docs/env-file.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ⚙️ Environment Variables File
# ⚙️ Environment Variables

This file defines environment variables used by VTMUNC. Note, that this env file is seperate from the environment variables for GitHub, where you need to paste in this environment variable file as a variable called ENV_FILE. Find out more from the [deployment docs](./deployment.md#-step-7-set-environment-variables-in-github)

Expand All @@ -12,8 +12,8 @@ Never, commit .env files to any remote repository, including GitHub. Only share
| AWS_DYNAMODB_SECRET_ACCESS_KEY | Your AWS DynamoDB secret access key. Refer to "Obtaining AWS Credentials Securely" to obtain this value. | `sb0lasoiwkdouwedfes` (fake) |
| AWS_DEFAULT_REGION | The default AWS region your application will use | `us-east1` |
| BACKEND_URL | The URL of your backend API | `localhost:3000/api` |
| USERNAME | The admin username | `[email protected]` (fake) |
| PASSWORD | The admin password | `randOMPassWordForMUN&283` (fake) |
| ADMIN_USERNAME | The admin username | `[email protected]` (fake) |
| ADMIN_PASSWORD | The admin password | `randOMPassWordForMUN&283` (fake) |
| JWT_SECRET | A secret key used for generating JSON Web Tokens (JWTs) for authentication. | `okmasfq;eiuidf` (fake) |

## Obtaining AWS Credentials Securely
Expand Down
4 changes: 2 additions & 2 deletions site/app/api/auth/login/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cookies } from "next/headers";
import { NextResponse } from "next/server";
import { encrypt, decrypt } from "@/lib";

const { USERNAME, PASSWORD, JWT_SECRET } = process.env;
const { ADMIN_USERNAME, ADMIN_PASSWORD, JWT_SECRET } = process.env;


export async function POST(request) {
Expand All @@ -11,7 +11,7 @@ export async function POST(request) {
const { userEmail, userPass } = body;

// Verify email and password against our env variables
if (userEmail === USERNAME && userPass === PASSWORD) {
if (userEmail === ADMIN_USERNAME && userPass === ADMIN_PASSWORD) {
// Create encrypted token with user email and expiration time
const expires = new Date(Date.now() + 3 * 60 * 60 * 1000);
const token = await encrypt({ userEmail, expires });
Expand Down

0 comments on commit adfcf88

Please sign in to comment.