Skip to content

Commit

Permalink
Merge pull request #18 from vevcom/feat/auth
Browse files Browse the repository at this point in the history
Feat/auth
  • Loading branch information
JohanHjelsethStorstad authored Oct 26, 2023
2 parents 67f23c8 + 99e50b5 commit e54fbc2
Show file tree
Hide file tree
Showing 27 changed files with 525 additions and 38 deletions.
12 changes: 12 additions & 0 deletions default.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# API Keys
GOOGLE_MAPS_API_KEY=HMMMMMMMMM

# Database
DB_NAME=devdb
DB_USERNAME=user
DB_PASSWORD=password

DB_URI="postgresql://${DB_USERNAME}:${DB_PASSWORD}@db:5432/${DB_NAME}"

# NextAuth
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET=cake_is_love_cake_is_life

# Next js
NEXT_TELEMETRY_DISABLED=1
9 changes: 6 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ services:
- ./package-lock.json:/usr/src/app/package-lock.json
- ./src/prisma/schema.prisma:/usr/src/app/src/prisma/schema.prisma
environment:
DB_URI: postgresql://${DB_USERNAME}:${DB_PASSWORD}@db:5432/${DB_NAME}
GOOGLE_MAPS_API_KEY: ${GOOGLE_MAPS_API_KEY}
NODE_ENV: development
DB_URI: ${DB_URI}
GOOGLE_MAPS_API_KEY: ${GOOGLE_MAPS_API_KEY}
NEXTAUTH_URL: ${NEXTAUTH_URL}
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
NEXT_TELEMETRY_DISABLED: ${NEXT_TELEMETRY_DISABLED}
depends_on:
- db
- prisma
Expand Down Expand Up @@ -46,7 +49,7 @@ services:
dockerfile: ./Dockerfile
target: dev
environment:
DB_URI: postgresql://${DB_USERNAME}:${DB_PASSWORD}@db:5432/${DB_NAME}
DB_URI: ${DB_URI}
volumes:
- ./src/prisma/schema.prisma:/usr/src/app/schema.prisma
depends_on:
Expand Down
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ services:
ports:
- 3000:3000
environment:
DB_URI: postgresql://${DB_USERNAME}:${DB_PASSWORD}@db:5432/${DB_NAME}
GOOGLE_MAPS_API_KEY: ${GOOGLE_MAPS_API_KEY}
NODE_ENV: production
DB_URI: ${DB_URI}
GOOGLE_MAPS_API_KEY: ${GOOGLE_MAPS_API_KEY}
NEXTAUTH_URL: ${NEXTAUTH_URL}
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
NEXT_TELEMETRY_DISABLED: ${NEXT_TELEMETRY_DISABLED}
depends_on:
- db
- prisma
Expand Down Expand Up @@ -41,7 +44,7 @@ services:
dockerfile: ./Dockerfile
target: prod
environment:
DB_URI: postgresql://${DB_USERNAME}:${DB_PASSWORD}@db:5432/${DB_NAME}
DB_URI: ${DB_URI}
depends_on:
db:
condition: service_healthy
Expand Down
120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"eslint-config-next": "13.4.19",
"google-map-react": "^2.2.1",
"next": "^13.5.4",
"next-auth": "^4.23.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-fontawesome": "^1.7.1",
Expand Down
18 changes: 18 additions & 0 deletions src/app/(auth)/CsrfToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use client"

import { getCsrfToken } from "next-auth/react"

async function CsrfToken() {
// getCsrfToken må kjøres på klientsiden*
// ellers så spytter den ut tilfedlig tokens
//
// * må og må, det finnes nok en bedre
// løsning men dette var den enkelste
const csrfToken = await getCsrfToken()

return (
<input name="csrfToken" type="hidden" defaultValue={csrfToken} />
)
}

export default CsrfToken
25 changes: 25 additions & 0 deletions src/app/(auth)/login/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Input from '@/app/components/Input/Input'
import styles from './page.module.scss'
import magiskHatt from "@/images/magisk_hatt.png"
import Image from 'next/image'
import PrimaryButton from '@/app/components/PrimaryButton/PrimaryButton'
import CsrfToken from '../CsrfToken'

export default async function LogIn() {
return (
<div className={styles.wrapper}>
<div className={styles.card}>
<form className={styles.form} method="post" action="/api/auth/callback/credentials">
<CsrfToken />
<Input name="username" label="E-post"/>
<Input name="password" label="Passord" type="password"/>

<PrimaryButton text="Logg inn"></PrimaryButton>
</form>
<div className={styles.image}>
<Image width={200} src={magiskHatt} />
</div>
</div>
</div>
)
}
28 changes: 28 additions & 0 deletions src/app/(auth)/login/page.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@use "@/styles/ohma";

.wrapper {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
> .card {
width: 60%;
padding: 4*ohma.$gap;
border-radius: 3em;

display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr;
background-color: ohma.$slate;
> form {
grid-column: 1/2;
max-width: 250px;
margin: auto;
}
> .image {
display: grid;
place-items: center;
grid-column: 2/3;
}
}
}
25 changes: 25 additions & 0 deletions src/app/(auth)/logout/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getCsrfToken } from "next-auth/react"

import styles from './page.module.scss'
import magiskHatt from "@/images/magisk_hatt.png"
import Image from 'next/image'
import PrimaryButton from '@/app/components/PrimaryButton/PrimaryButton'
import CsrfToken from '../CsrfToken'

export default async function LogOut() {
const csrfToken = await getCsrfToken()

return (
<div className={styles.wrapper}>
<div className={styles.card}>
<form className={styles.form} method="post" action="/api/auth/signout">
<CsrfToken />
<PrimaryButton text="Logg ut"></PrimaryButton>
</form>
<div className={styles.image}>
<Image width={200} src={magiskHatt} />
</div>
</div>
</div>
)
}
Loading

0 comments on commit e54fbc2

Please sign in to comment.