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 106 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
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ yarn-error.log*

# local env files
.env*.local
.env*.production

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# cypress
/cypress/screenshots
/cypress/videos
cypress.env.json
46 changes: 46 additions & 0 deletions .github/workflows/preview_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Cypress Tests

on:
push:
branches-ignore:
- main
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 cypress.env.json
run: |
echo '${{ secrets.CYPRESS_ENV_CI }}' > cypress.env.json
- name: Write .env
run: |
echo "${{ secrets.ENV_TEST_LOCAL }}" > .env
- 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 }}
config: baseUrl=${{ 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
config: baseUrl=${{ secrets.CYPRESS_BASE_URL }}
wait-on: ${{ secrets.CYPRESS_BASE_URL }}
browser: chrome
record: true
23 changes: 0 additions & 23 deletions .github/workflows/tests.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/vercel_preview_deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Vercel Preview Deploymentga .
ketphan02 marked this conversation as resolved.
Show resolved Hide resolved

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

on:
push:
branches-ignore:
- main

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
ketphan02 marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

# Loggings
/logs

# cypress
/cypress/screenshots
/cypress/videos
cypress.env.json
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# cypress
/cypress/screenshots
/cypress/videos
cypress.env.json
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ docker-compose -f dev-docker-compose.yml up -d

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

### Apply latest database migrations

```bash
npx prisma db push
```

### Linting the Project

Run the following to lint and format the project
Expand All @@ -48,15 +54,29 @@ npm run lint
Run the following to open Cypress

```bash
cypress open
npm run cypress:open
```

### Development environment variable

Add this following code to a `.env` file
Please view in private channel #dotenv

```dotenv
DATABASE_URL="postgresql://postgres:password123@localhost:5432/postgres?schema=dev"
### Database migration

If you make changes to prisma models, you can migrate the database by

```bash
npx prisma migrate dev --name <migration-name>
ketphan02 marked this conversation as resolved.
Show resolved Hide resolved
```

Note: `migration-name` should be a short description of the changes you made

### Database exploration

You can view your tables, columns, and make changes to your local database by

```bash
npm run prisma:explore
```

## Chosen Project
Expand Down
7 changes: 7 additions & 0 deletions 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({
projectId: process.env.CYPRESS_PROJECT_ID,
e2e: {
baseUrl: process.env.NEXT_PUBLIC_BASE_URL,
setupNodeEvents(on, config) {
// implement node event listeners here
on('task', {
clearDB,
})
},
experimentalModifyObstructiveThirdPartyCode: true,
},

component: {
Expand Down
File renamed without changes.
56 changes: 56 additions & 0 deletions cypress/e2e/app/signin.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { DELAY, TIMEOUT } from '../../utils/constants'
import { getHeaders } from '../../utils/headers'

describe.skip('Test auth', () => {
before(() => {
cy.task('clearDB')
})
it('should log in with google', () => {
// TODO: Visit landing page, check if logged in, if not, redirect to /signin instead of visit /signin directly
cy.visit('/signin', { headers: getHeaders() })
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.url({ timeout: TIMEOUT.EXTRA_LONG }).should('eq', '')
cy.origin(
'https://accounts.google.com',
{
args: {
username: Cypress.env('GOOGLE_USER'),
password: Cypress.env('GOOGLE_PW'),
cookieName: Cypress.env('COOKIE_NAME'),
TIMEOUT: TIMEOUT,
DELAY: DELAY,
},
},
({ username, password, cookieName, TIMEOUT, DELAY }) => {
Cypress.on(
'uncaught:exception',
(err) =>
!err.message.includes('ResizeObserver loop') &&
!err.message.includes('Error in protected function')
)

// Type username
cy.get('input[type=email]', { timeout: TIMEOUT.MEDIUM }).should('be.visible').type(username)
cy.get('button').contains('Next').click()

// Type password
cy.get('input[type=password]', { timeout: TIMEOUT.LONG }).as('pwfInp')
cy.get('@pwfInp')
.should('be.visible')
.then(($pwfInp) => {
// find the one that is not hidden
const $visiblePwfInp = $pwfInp.filter((i, el) => {
return !Cypress.$(el).is(':hidden')
})
cy.wrap($visiblePwfInp).type(password)
cy.get('button').contains('Next').click()
})
}
)

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

require('dotenv').config()

export default async function clearDB() {
console.log(process.env.DATABASE_URL)

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,
}
5 changes: 5 additions & 0 deletions cypress/utils/headers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const getHeaders = () => ({
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
})
Loading
Loading