Skip to content
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

Added Authentication and User creation #41

Merged
merged 150 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
36d686f
Added Authentication and User creation
Oct 5, 2023
0ddff10
- Added login page that only supports Google login and has minimal st…
Oct 6, 2023
fe97aa3
Remove foo
Oct 6, 2023
055ec5b
Added new environment variables and migration guild in readme
Oct 6, 2023
8a384d3
Merge branch with latest master branch
Oct 6, 2023
fe55998
Run lint for every changed files
Oct 6, 2023
c5a4f29
Merge branch 'master' into 38-create-user-model
Oct 6, 2023
880e642
Clarify and update README
Oct 6, 2023
1acbc4a
Update README for db exploration and update init migration
Oct 6, 2023
c4078b5
Clarify readme for db migration
Oct 6, 2023
f75ec40
- Resolve conflict and catch up with main
Oct 13, 2023
60f4c8b
Resolve comments
Oct 13, 2023
c0163f3
Run lint
Oct 13, 2023
94a7d7a
Merge Cypress set up
Oct 13, 2023
b619ec5
Run lint
Oct 13, 2023
57250fa
Merge main
Oct 18, 2023
ae1899a
Make husky executable
Oct 18, 2023
5531447
Download dependecies
Oct 18, 2023
fcf62a7
Add cross-env to manage environments
Oct 18, 2023
ef561e8
Use dotenv-cli instead of cross-env
Oct 18, 2023
1e600e7
E2E test for login by google
Oct 18, 2023
a55d63e
Remove auth API test since using third party
Oct 18, 2023
ca6c7f9
Self evaluation
Oct 18, 2023
b24b29d
Modify to eliminate cookies issue
Oct 18, 2023
7e5fe43
Update README.md
ketphan02 Oct 18, 2023
c15ccf7
Update actions
Oct 18, 2023
391320d
Merge branch '38-create-user-model' of github.com:COSC-499-W2023/year…
Oct 18, 2023
c792a1c
Add debug flag to check failure
Oct 18, 2023
a154408
try using records
Oct 18, 2023
b10d626
Update the environment path
Oct 18, 2023
418cc4c
Add project id for e2e
Oct 18, 2023
d3e44c1
Add github token
Oct 19, 2023
4f24903
Add github token
Oct 19, 2023
67654a2
Build and start with .env.test.local
Oct 19, 2023
106e6fe
Use .env instead of .env.test.local
Oct 19, 2023
1b98087
remove debuging
Oct 19, 2023
c559fe2
Add longer wait period
Oct 19, 2023
20c3422
Configs so the test will run
Oct 19, 2023
6e52022
Remove clearDB since no db
Oct 19, 2023
1d934ce
No need dotenv load
Oct 19, 2023
f8e00b0
Actually, we need it
Oct 19, 2023
ff1cd9d
Modify wait time
Oct 19, 2023
f9284fc
Modify wait time
Oct 19, 2023
3741593
Add more time to wait
Oct 19, 2023
0e3f8c3
Check for location
Oct 19, 2023
9ac7143
Check locations
Oct 19, 2023
e52919d
Dont let it run too long
Oct 19, 2023
3117ea2
Remove debuging, make fail quicker
Oct 19, 2023
1a037d3
Better pipeline
Oct 19, 2023
1a75b03
Better pipeline
Oct 19, 2023
2fdaa7e
Better pipeline
Oct 19, 2023
966dfb8
Better pipeline
Oct 19, 2023
48ca4c4
Sacve logs
Oct 19, 2023
35010f0
Save logs
Oct 19, 2023
cd2ff93
Get logs
Oct 20, 2023
7db4165
Get logs
Oct 20, 2023
39110bc
Get logs
Oct 20, 2023
ae5cd5d
Make process in background
Oct 20, 2023
62c8591
Add logger and use it to see what went wrong
Oct 20, 2023
9f9fd5c
Remove logger prettifier
Oct 20, 2023
7d03e02
Remove logger prettifier
Oct 20, 2023
6dfd1df
Collect only if fail
Oct 20, 2023
b60f875
Enable debug for nextauth
Oct 20, 2023
11c279f
Search for error
Oct 20, 2023
dfe4c83
Problem 1: Wait time not enough
Oct 20, 2023
0d32d95
REmove env file
Oct 20, 2023
b38f8d8
REmove env file
Oct 20, 2023
b8789e4
Matrix update
Oct 20, 2023
0eb31be
Remove matrix and update new credentials
Oct 20, 2023
7585763
Use electron since google flagged chrome
Oct 20, 2023
36b5e55
Change to Edge
Oct 20, 2023
0e39d3e
Change back to Chrome and update useragent
Oct 21, 2023
3ea4a2d
Use electron
Oct 21, 2023
454c7d8
Wrong use of group
Oct 21, 2023
780e2e9
Run local db
Oct 21, 2023
af67ae2
Local db does not work
Oct 21, 2023
3b97300
Add .env for prod
Oct 21, 2023
6d45e9e
Add clear db to test if the db is connected
Oct 21, 2023
631aca5
We use single quote in .env, so should wrap by double quote
Oct 21, 2023
1169e13
Run on my machine
Oct 21, 2023
d12c7dd
Skip test auth since google is flagging
Oct 21, 2023
21a5c1f
Removing skip
Oct 21, 2023
fa2e2cd
Put skip again
Oct 21, 2023
c1bd280
Try running of deployment
Oct 22, 2023
0d3404b
Preview deployment set up
Oct 22, 2023
1ed76bd
Update env
Oct 22, 2023
6f6c423
Resolve prisma issue
Oct 22, 2023
c87214d
Push .env to deployment
Oct 22, 2023
1ae82e4
Saving deployment URL as artifact
Oct 22, 2023
96909d2
Token
Oct 22, 2023
2da6032
Use project id
Oct 22, 2023
3d74734
Specify org_id
Oct 22, 2023
9091830
No need to save url
Oct 22, 2023
408ba3b
No environment needed
Oct 22, 2023
1a0c7ab
Not gonna work but worth a try:
Oct 22, 2023
1ab3176
Merge main
Oct 22, 2023
a0c9330
Add alias
Oct 22, 2023
be8aa19
This might work?
Oct 22, 2023
33c95fb
This will work
Oct 22, 2023
658dca8
Tests should run after deployment
Oct 22, 2023
3dab4b7
Tests should run after deployment
Oct 22, 2023
3702590
Allow installing dependencies
Oct 22, 2023
9e90cd1
Remove CYPRESS_BASE_URL env
Oct 22, 2023
9c5d3fc
Change to Chrome
Oct 22, 2023
90490e1
Not skipping google login
Oct 22, 2023
750811b
Skip, it's not working bro, I'm sad, but at least it's running well
Oct 22, 2023
f818e09
Remove node_modules in docker-compose
Oct 24, 2023
4c260da
Finished testing with cypress
Oct 26, 2023
fb4a5a1
Clean up cypress
Oct 26, 2023
1446366
Ignore docs and README when running tests
Oct 26, 2023
ae9afde
Update .github/workflows/vercel_preview_deployment.yml
ketphan02 Oct 26, 2023
60d9f35
Resolve merge conflicts
Oct 26, 2023
fbdf31c
Merge branch '38-create-user-model' of github.com:COSC-499-W2023/year…
Oct 26, 2023
580de05
No logs needed for now
Oct 26, 2023
d9e0c56
Disable debug
Oct 26, 2023
f266caa
Clean up
Oct 26, 2023
54f152d
Add .env guard
Oct 27, 2023
2290928
Add .env guard
Oct 27, 2023
45a4045
Update docker to run dev
Oct 27, 2023
cadee73
Make docker runs and update documentation
Oct 27, 2023
415acaa
Update command with correct param
Oct 27, 2023
65bbc6a
Update command with correct param
Oct 27, 2023
6e598d1
Correcting the docs
Oct 27, 2023
f7e3d3b
Update docs
Oct 27, 2023
b486eb5
update environment variables for test
Oct 27, 2023
291a5bc
Update workflow
Oct 27, 2023
63aae88
Update workflow
Oct 27, 2023
ba2fa94
Merge branch '38-create-user-model' of github.com:COSC-499-W2023/year…
Oct 27, 2023
e4e21c3
No NODE_ENV
Oct 27, 2023
71257da
Modify workflow
Oct 27, 2023
2a9e86c
Alias for cypressProjectId
Oct 27, 2023
019f668
Modify workflow
Oct 27, 2023
28b6021
Modify workflow
Oct 27, 2023
b2a74f7
Modify workflow
Oct 27, 2023
7fbd5b3
Modify workflow
Oct 27, 2023
7831436
Update prisma/schema.prisma
ketphan02 Oct 28, 2023
8549b95
Update prisma/migrations/migration_lock.toml
ketphan02 Oct 28, 2023
56569c0
Update .dockerignore
ketphan02 Oct 28, 2023
e364bbf
Merge branch 'master' into 38-create-user-model
Oct 28, 2023
908a222
Run lint
Oct 28, 2023
2873c2b
Resolve conflicts
Oct 28, 2023
bafe7f8
Revert unwanted lint
Oct 28, 2023
310f230
Revert unwanted lint
Oct 28, 2023
0245f43
Revert unwanted lint
Oct 28, 2023
909d098
Revert unwanted lint
Oct 28, 2023
5e287c9
Revert unwanted lint
Oct 28, 2023
3b935ea
Ignore linting for docs
Oct 28, 2023
6042c7a
Update docs for local dev
Oct 28, 2023
d54bcc6
Update tests with new dashboard
Oct 28, 2023
1ed91f8
Clean up
Oct 28, 2023
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
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ cypress

# Exclude configuration files
.dockerignore
.env
.eslint*
.gitignore
.lintstagedrc.js
Expand All @@ -25,3 +24,7 @@ docs
*.md

npm-debug.log

# Environment variables
.env
.env*.local
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# docs
docs/**/*
*.md
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
with:
node-version: '18.18.0'
- run: npm ci
- name: Write environment variables
ketphan02 marked this conversation as resolved.
Show resolved Hide resolved
run: |
echo "${{ secrets.ENV_TEST_LOCAL }}" > .env
echo "" > cypress.config.json
- name: ESLint
run: npm run lint
- name: Prettier
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/preview_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Cypress Tests

on:
push:
branches-ignore:
- main
paths-ignore:
- docs/**
- README.md
jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- name: Wait for preview deployment
uses: lewagon/[email protected]
with:
ref: ${{ github.ref }}
check-name: 'Deploy Preview'
repo-token: ${{ secrets.PERSONAL_GITHUB_ACCESS_TOKEN }}
wait-interval: 10
- name: Checkout
uses: actions/checkout@v4
- name: Write environment variables
run: |
echo "${{ secrets.ENV_TEST_LOCAL }}" > .env
echo "" > cypress.config.json
- name: Migrate Database
run: npx prisma migrate dev
- name: Cypress Run Component Tests
uses: cypress-io/github-action@v6
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_ACCESS_TOKEN }}
with:
browser: chrome
component: true
wait-on: ${{ secrets.CYPRESS_BASE_URL }}
- name: Cypress Run E2E Tests
uses: cypress-io/github-action@v6
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_ACCESS_TOKEN }}
with:
install: false
wait-on: ${{ secrets.CYPRESS_BASE_URL }}
browser: chrome
record: true
23 changes: 0 additions & 23 deletions .github/workflows/tests.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/vercel_preview_deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Vercel Preview Deployment .

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

on:
push:
branches-ignore:
- main
paths-ignore:
- docs/**
- README.md

jobs:
deploy-preview:
name: Deploy Preview
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Write .env
run: |
echo "${{ secrets.ENV_PREVIEW }}" > .env
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: |
url="$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})"
vercel alias --token=${{ secrets.VERCEL_TOKEN }} set "$url" ubco-capstone-team-3.vercel.app
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# docs
docs/**/*
*.md
13 changes: 0 additions & 13 deletions Dockerfile

This file was deleted.

28 changes: 28 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:18-alpine
ketphan02 marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /app

COPY package*.json ./

COPY prisma ./prisma

ARG $ARG_DATABASE_URL
ENV DATABASE_URL $ARG_DATABASE_URL
ARG $ARG_NEXTAUTH_URL
ENV NEXTAUTH_URL $ARG_NEXTAUTH_URL

RUN npm install

COPY . .

RUN rm -rf prisma

RUN mkdir -p .next
RUN chown node:node . node_modules .next
RUN chown -R node:node node_modules/.prisma

USER node

EXPOSE 3000

CMD ["npm", "run", "dev"]
45 changes: 5 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,19 @@

## Project Setup

First, run the development server:

### Requirements

- [NodeJS 18.18](https://nodejs.org/en)
- [Docker Desktop](https://www.docker.com/products/docker-desktop/)

### Installing Dependencies

Run the following command to install dependencies

```bash
npm install
```

### Running the Project and the Database

Run the following to start the project and run the dev database

```bash
docker-compose -f dev-docker-compose.yml up -d
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
### Step-by-step guide

### Linting the Project
- [Local Development Setup](docs/guides/local_development_setup.md)
- [Local Docker Development Setup](docs/guides/local_docker_development_setup.md)

Run the following to lint and format the project
### Common commands

```bash
npm run lint
```

### Testing the Project

Run the following to open Cypress

```bash
cypress open
```

### Development environment variable

Add this following code to a `.env` file

```dotenv
DATABASE_URL="postgresql://postgres:password123@localhost:5432/postgres?schema=dev"
```
- [Common commands](docs/guides/commands.md)

## Chosen Project

Expand Down
9 changes: 8 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { defineConfig } from 'cypress'
import clearDB from './cypress/tasks/clearDB'

require('dotenv').config()

export default defineConfig({
e2e: {
baseUrl: process.env.NEXT_PUBLIC_BASE_URL,
projectId: process.env.CYPRESS_PROJECT_ID,
baseUrl: process.env.CYPRESS_BASE_URL,
setupNodeEvents(on, config) {
// implement node event listeners here
on('task', {
clearDB,
})
},
experimentalModifyObstructiveThirdPartyCode: true,
},

component: {
Expand Down
4 changes: 2 additions & 2 deletions cypress/component/demo-component.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ describe('Demo Component', () => {
it('Default Message', () => {
cy.mount(<Demo />)
cy.get('#message').should('have.text', 'Hello World! Good Morning')
cy.get('#date').should('have.text', "Today's date is: " + dateNow)
cy.get('#date').should('have.text', 'Today\'s date is: ' + dateNow)
ketphan02 marked this conversation as resolved.
Show resolved Hide resolved
})
it('Good Evening Message', () => {
cy.mount(<Demo greetings='Good Evening' />)
cy.get('#message').should('have.text', 'Hello World! Good Evening')
cy.get('#date').should('have.text', "Today's date is: " + dateNow)
cy.get('#date').should('have.text', 'Today\'s date is: ' + dateNow)
})
})
File renamed without changes.
37 changes: 37 additions & 0 deletions cypress/e2e/app/signin.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { TIMEOUT } from '../../utils/constants'

describe('Test auth', () => {
ketphan02 marked this conversation as resolved.
Show resolved Hide resolved
before(() => {
cy.task('clearDB')
cy.intercept(
{
method: 'GET',
url: 'https://accounts.google.com/o/oauth2/v2/auth?*',
},
(req) => {
const redirectUri = req.query['redirect_uri'] as string
const state = req.query['state'] as string
const code = req.query['code'] as string
const scope = req.query['scope'] as string
const authuser = req.query['authuser'] as number
const prompt = req.query['prompt'] as string
const url = `${ redirectUri }?code=${ code }&state=${ state }&scope=${ scope }&authuser=${ authuser }&prompt=${ prompt }`
req.redirect(url, 302)
}
).as('googleSignIn')
cy.intercept('/api/auth/callback/google?*', (req) => {
req.redirect('/', 302)
}).as('googleSignInCallback')
})
it('should log in with google', () => {
cy.visit('/')
cy.get('[data-cy="login-button"]').click()

cy.get('h1').should('include.text', 'Sign In Page')
cy.get('[data-cy="google-sign-in-btn"]').should('include.text', 'Sign in with Google').click()
cy.wait(['@googleSignInCallback'], { timeout: TIMEOUT.EXTRA_LONG })

cy.location('origin', { timeout: TIMEOUT.EXTRA_LONG }).should('eq', Cypress.config().baseUrl)
cy.location('pathname').should('eq', '/')
})
})
8 changes: 8 additions & 0 deletions cypress/tasks/clearDB.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import prisma from '@/lib/prisma'

export default async function clearDB() {
await prisma.account.deleteMany({})
await prisma.user.deleteMany({})

return null
}
15 changes: 15 additions & 0 deletions cypress/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const TIMEOUT = {
EXTRA_SHORT: 500,
SHORT: 1000,
MEDIUM: 3000,
LONG: 6000,
EXTRA_LONG: 8000,
}

export const DELAY = {
EXTRA_SHORT: 500,
SHORT: 1000,
MEDIUM: 3000,
LONG: 6000,
EXTRA_LONG: 8000,
}
24 changes: 0 additions & 24 deletions dev-docker-compose.yml

This file was deleted.

Loading
Loading