Skip to content

Commit

Permalink
🔀 Add basic authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw authored Sep 24, 2023
2 parents c777a77 + 76008aa commit c1b3bc4
Show file tree
Hide file tree
Showing 285 changed files with 10,886 additions and 5,197 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ npm-debug.log
.github
LICENSE
docs/
*.sqlite
*.env
.env
.next/standalone/.env
23 changes: 23 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Since the ".env" file is gitignored, you can use the ".env.example" file to
# build a new ".env" file when you clone the repo. Keep this file up-to-date
# when you add new variables to `.env`.

# This file will be committed to version control, so make sure not to have any
# secrets in it. If you are cloning this repo, create a copy of this file named
# ".env" and populate it with your secrets.

# When adding additional environment variables, the schema in "/src/env.js"
# should be updated accordingly.

# Prisma
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
DATABASE_URL="file:../database/db.sqlite"

# Next Auth
# You can generate a new secret on the command line with:
# openssl rand -base64 32
# https://next-auth.js.org/configuration/options#secret
# NEXTAUTH_SECRET=""
NEXTAUTH_URL="http://localhost:3000"

NEXTAUTH_SECRET=""
6 changes: 5 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- run: yarn install --immutable

- run: yarn build
- run: yarn turbo build

- name: Docker meta
id: meta
Expand All @@ -83,6 +83,9 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver: docker
buildkitd-flags: --debug

- name: Login to GHCR
uses: docker/login-action@v2
Expand All @@ -101,3 +104,4 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
network: host
8 changes: 7 additions & 1 deletion .github/workflows/docker_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
permissions:
packages: write
contents: read
pull-requests: write
steps:

- name: Setup
Expand Down Expand Up @@ -74,7 +75,11 @@ jobs:

- run: yarn turbo build

- run: yarn test:run
- run: yarn test:coverage

- name: Report coverage
if: always()
uses: davelosert/vitest-coverage-report-action@v2

- name: Docker meta
if: github.event_name != 'pull_request'
Expand Down Expand Up @@ -114,3 +119,4 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
network: host
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ data/configs

#Languages other than 'en'
public/locales/*
!public/locales/en
!public/locales/en

#database
prisma/db.sqlite
database/*.sqlite

# IDE
.idea/*
19 changes: 16 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM node:20-alpine
FROM node:20.5-slim
WORKDIR /app

# Define node.js environment variables
ARG PORT=7575

ENV NEXT_TELEMETRY_DISABLED 1
Expand All @@ -10,16 +11,28 @@ ENV NODE_OPTIONS '--no-experimental-fetch'
COPY next.config.js ./
COPY public ./public
COPY package.json ./package.json

COPY yarn.lock ./yarn.lock
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY .next/standalone ./
COPY .next/static ./.next/static
COPY prisma/schema.prisma prisma/schema.prisma
COPY ./scripts/run.sh ./scripts/run.sh

# Install dependencies
RUN apt-get update -y && apt-get install -y openssl
RUN yarn global add prisma

# Expose the default application port
EXPOSE $PORT
ENV PORT=${PORT}

ENV DATABASE_URL "file:../database/db.sqlite"
ENV NEXTAUTH_URL "http://localhost:3000"
ENV PORT 7575
ENV NEXTAUTH_SECRET NOT_IN_USE_BECAUSE_JWTS_ARE_UNUSED

HEALTHCHECK --interval=10s --timeout=5s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:${PORT} || exit 1

CMD ["node", "server.js"]
CMD ["sh", "./scripts/run.sh"]
2 changes: 1 addition & 1 deletion data/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
"pageTitle": "Homarr ⭐️",
"logoImageUrl": "/imgs/logo/logo.png",
"faviconUrl": "/imgs/favicon/favicon-squared.png",
"backgroundImageUrl": "",
"backgroundImageUrl": "https://images.unsplash.com/32/Mc8kW4x9Q3aRR3RkP5Im_IMG_4417.jpg?ixid=M3wxMjA3fDB8MXxzZWFyY2h8MTV8fGJhY2tncm91bmQlMjBpbWFnZXxlbnwwfHx8fDE2OTE0NDQ5NjF8MA&ixlib=rb-4.0.3",
"customCss": "",
"colors": {
"primary": "red",
Expand Down
2 changes: 2 additions & 0 deletions data/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const REPO_URL = 'ajnart/homarr';
export const ICON_PICKER_SLICE_LIMIT = 36;
export const COOKIE_LOCALE_KEY = 'config-locale';
export const COOKIE_COLOR_SCHEME_KEY = 'color-scheme';
4 changes: 2 additions & 2 deletions next-i18next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ module.exports = {
'no',
'tr',
'lv',
'hu',
'hr'
'hr',
'hu'
],

localeDetection: true,
Expand Down
11 changes: 11 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('./src/env');
const { i18n } = require('./next-i18next.config');

const withBundleAnalyzer = require('@next/bundle-analyzer')({
Expand All @@ -12,4 +13,14 @@ module.exports = withBundleAnalyzer({
output: 'standalone',
i18n,
transpilePackages: ['@jellyfin/sdk'],
redirects: async () => [
{
source: '/',
destination: '/board',
permanent: false,
},
],
env: {
NEXTAUTH_URL_INTERNAL: process.env.NEXTAUTH_URL_INTERNAL || process.env.HOSTNAME || 'http://localhost:3000'
},
});
34 changes: 26 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homarr",
"version": "0.13.4",
"version": "0.13.2",
"description": "Homarr - A homepage for your server.",
"license": "MIT",
"repository": {
Expand All @@ -9,9 +9,9 @@
},
"scripts": {
"dev": "next dev",
"build": "next build",
"build": "NEXTAUTH_SECRET=WILL_BE_OVERWRITTEN next build",
"analyze": "ANALYZE=true next build",
"turbo": "turbo run build",
"turbo": "DATABASE_URL=file:WILL_BE_OVERWRITTEN.sqlite NEXTAUTH_URL=http://WILL_BE_OVERWRITTEN turbo build",
"start": "next start",
"typecheck": "tsc --noEmit",
"export": "next build && next export",
Expand All @@ -22,8 +22,9 @@
"test:ui": "vitest --ui",
"test:run": "vitest run",
"test:coverage": "vitest run --coverage",
"docker:build": "turbo build && docker build . -t homarr:dev",
"docker:start": "docker run --env-file ./.env -p 7575:7575 homarr:dev "
"docker:build": "turbo build && docker build . -t homarr:local-dev",
"docker:start": "docker run -p 7575:7575 --name homarr-development homarr:local-dev",
"postinstall": "prisma generate"
},
"dependencies": {
"@ctrl/deluge": "^4.1.0",
Expand All @@ -41,10 +42,14 @@
"@mantine/modals": "^6.0.0",
"@mantine/next": "^6.0.0",
"@mantine/notifications": "^6.0.0",
"@mantine/prism": "^6.0.19",
"@mantine/tiptap": "^6.0.17",
"@next-auth/prisma-adapter": "^1.0.7",
"@nivo/core": "^0.83.0",
"@nivo/line": "^0.83.0",
"@prisma/client": "^5.0.0",
"@react-native-async-storage/async-storage": "^1.18.1",
"@t3-oss/env-nextjs": "^0.6.0",
"@tabler/icons-react": "^2.20.0",
"@tanstack/query-async-storage-persister": "^4.27.1",
"@tanstack/query-sync-storage-persister": "^4.27.1",
Expand All @@ -59,29 +64,40 @@
"@trpc/next": "^10.29.1",
"@trpc/react-query": "^10.29.1",
"@trpc/server": "^10.29.1",
"@types/bcryptjs": "^2.4.2",
"@vitejs/plugin-react": "^4.0.0",
"axios": "^1.0.0",
"bcryptjs": "^2.4.3",
"browser-geo-tz": "^0.0.4",
"consola": "^3.0.0",
"cookies": "^0.8.0",
"cookies-next": "^2.1.1",
"dayjs": "^1.11.7",
"dockerode": "^3.3.2",
"fily-publish-gridstack": "^0.0.13",
"flag-icons": "^6.9.2",
"framer-motion": "^10.0.0",
"generate-password": "^1.7.0",
"geo-tz": "^7.0.7",
"html-entities": "^2.3.3",
"i18next": "^22.5.1",
"immer": "^10.0.2",
"js-file-download": "^0.4.12",
"moment": "^2.29.4",
"moment-timezone": "^0.5.43",
"next": "13.4.12",
"next-i18next": "^13.0.0",
"next-auth": "^4.22.3",
"next-i18next": "^14.0.0",
"nzbget-api": "^0.0.3",
"prisma": "^5.0.0",
"prismjs": "^1.29.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^12.3.1",
"react-simple-code-editor": "^0.13.1",
"rss-parser": "^3.12.0",
"sabnzbd-api": "^1.5.0",
"sharp": "^0.32.4",
"uuid": "^9.0.0",
"xml-js": "^1.6.11",
"xss": "^1.0.14",
Expand All @@ -94,6 +110,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
"@types/cookies": "^0.7.7",
"@types/dockerode": "^3.3.9",
"@types/node": "18.17.8",
"@types/prismjs": "^1.26.0",
Expand All @@ -103,7 +120,8 @@
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitest/coverage-c8": "^0.33.0",
"@vitest/ui": "^0.33.0",
"@vitest/coverage-v8": "^0.34.5",
"@vitest/ui": "^0.34.4",
"eslint": "^8.0.1",
"eslint-config-next": "^13.4.5",
"eslint-plugin-promise": "^6.0.0",
Expand All @@ -117,7 +135,7 @@
"prettier": "^3.0.0",
"sass": "^1.56.1",
"ts-node": "latest",
"turbo": "latest",
"turbo": "^1.10.12",
"typescript": "^5.1.0",
"video.js": "^8.0.3",
"vite-tsconfig-paths": "^4.2.0",
Expand Down
93 changes: 93 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "linux-musl-openssl-3.0.x", "linux-musl-arm64-openssl-3.0.x", "debian-openssl-3.0.x"]
}

datasource db {
provider = "sqlite"
// NOTE: When using mysql or sqlserver, uncomment the @db.Text annotations in model Account below
// Further reading:
// https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
url = env("DATABASE_URL")
}

// Necessary for Next auth
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? // @db.Text
access_token String? // @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? // @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}

model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
password String?
salt String?
isAdmin Boolean @default(false)
isOwner Boolean @default(false)
accounts Account[]
sessions Session[]
settings UserSettings?
createdInvites Invite[]
}

model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}

model Invite {
id String @id @default(cuid())
token String @unique
expires DateTime
createdById String
createdBy User @relation(fields: [createdById], references: [id], onDelete: Cascade)
}

model UserSettings {
id String @id @default(cuid())
userId String
colorScheme String @default("environment") // environment, light, dark
language String @default("en")
defaultBoard String @default("default")
firstDayOfWeek String @default("monday") // monday, saturnday, sunday
searchTemplate String @default("https://google.com/search?q=%s")
openSearchInNewTab Boolean @default(true)
disablePingPulse Boolean @default(false)
replacePingWithIcons Boolean @default(false)
useDebugLanguage Boolean @default(false)
autoFocusSearch Boolean @default(false)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([userId])
}
1 change: 1 addition & 0 deletions public/imgs/app-icons/truenas.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/imgs/app-icons/unraid-alt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c1b3bc4

Please sign in to comment.