diff --git a/backend/package.json b/backend/package.json index c9be93b..d07e24b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -29,7 +29,6 @@ "bcrypt": "^5.0.1", "class-transformer": "^0.5.1", "class-validator": "^0.13.2", - "fastify": "^3.27.2", "fastify-multipart": "^5.3.1", "fastify-static": "^4.5.0", "file-type": "^17.1.1", @@ -37,11 +36,11 @@ "passport-jwt": "^4.0.0", "passport-local": "^1.0.0", "pg": "^8.7.3", + "picsur-shared": "*", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^7.5.4", - "typeorm": "^0.2.44", - "picsur-shared": "*" + "typeorm": "^0.2.44" }, "devDependencies": { "@nestjs/cli": "^8.2.1", diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 003ff56..70a4e31 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -1,4 +1,4 @@ -import { Module } from '@nestjs/common'; +import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { AuthModule } from './routes/api/auth/auth.module'; import { ImageModule } from './routes/image/imageroute.module'; @@ -29,4 +29,5 @@ import { EImage } from 'picsur-shared/dist/entities/image.entity'; DemoManagerModule, ], }) -export class AppModule {} +export class AppModule { +} diff --git a/backend/src/main.ts b/backend/src/main.ts index 5b7c012..e1a15b4 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -23,7 +23,7 @@ async function bootstrap() { ); app.useGlobalFilters(new MainExceptionFilter()); app.useGlobalInterceptors(new SuccessInterceptor()); - app.useGlobalPipes(new ValidationPipe({ disableErrorMessages: true })); + app.useGlobalPipes(new ValidationPipe({ disableErrorMessages: true, forbidUnknownValues: true })); await app.listen(Config.main.port, Config.main.host); } diff --git a/backend/src/routes/api/auth/auth.controller.ts b/backend/src/routes/api/auth/auth.controller.ts index 6d479c7..1bd7f4b 100644 --- a/backend/src/routes/api/auth/auth.controller.ts +++ b/backend/src/routes/api/auth/auth.controller.ts @@ -15,7 +15,12 @@ import { JwtAuthGuard } from './jwt.guard'; import { AdminGuard } from './admin.guard'; import { HasFailed } from 'picsur-shared/dist/types'; import AuthFasityRequest from './authrequest'; -import { AuthDeleteRequest, AuthLoginResponse, AuthRegisterRequest } from 'picsur-shared/dist/dto/auth.dto'; +import { + AuthDeleteRequest, + AuthLoginResponse, + AuthMeResponse, + AuthRegisterRequest, +} from 'picsur-shared/dist/dto/auth.dto'; @Controller('api/auth') export class AuthController { @@ -77,6 +82,10 @@ export class AuthController { @UseGuards(JwtAuthGuard) @Get('me') async me(@Request() req: AuthFasityRequest) { - return req.user; + const meResponse: AuthMeResponse = new AuthMeResponse(); + meResponse.user = req.user; + meResponse.newJwtToken = await this.authService.createToken(req.user); + + return meResponse; } } diff --git a/backend/src/routes/api/auth/auth.module.ts b/backend/src/routes/api/auth/auth.module.ts index a3b9612..5d88a83 100644 --- a/backend/src/routes/api/auth/auth.module.ts +++ b/backend/src/routes/api/auth/auth.module.ts @@ -1,4 +1,10 @@ -import { Logger, Module, OnModuleInit } from '@nestjs/common'; +import { + Logger, + MiddlewareConsumer, + Module, + NestModule, + OnModuleInit, +} from '@nestjs/common'; import { PassportModule } from '@nestjs/passport'; import { AuthService } from './auth.service'; import { LocalStrategy } from './local.strategy'; @@ -27,7 +33,6 @@ export class AuthModule implements OnModuleInit { onModuleInit() { this.checkJwtSecret(); - this.ensureAdminExists(); } diff --git a/backend/src/routes/api/auth/auth.service.ts b/backend/src/routes/api/auth/auth.service.ts index 5dfbfc6..d9c234c 100644 --- a/backend/src/routes/api/auth/auth.service.ts +++ b/backend/src/routes/api/auth/auth.service.ts @@ -1,7 +1,7 @@ import { Injectable, Logger } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import * as bcrypt from 'bcrypt'; -import { plainToClass } from 'class-transformer'; +import { instanceToPlain, plainToClass } from 'class-transformer'; import { validate } from 'class-validator'; import { JwtDataDto } from 'picsur-shared/dist/dto/auth.dto'; import { EUser } from 'picsur-shared/dist/entities/user.entity'; @@ -51,7 +51,7 @@ export class AuthService { throw new Error('Invalid jwt token generated'); } - return this.jwtService.signAsync(jwtData); + return this.jwtService.signAsync(instanceToPlain(jwtData)); } async makeAdmin(user: string | EUser): AsyncFailable { diff --git a/frontend/public/fonts/opensans.css b/frontend/public/css/opensans.css similarity index 94% rename from frontend/public/fonts/opensans.css rename to frontend/public/css/opensans.css index 0284909..b6bbe41 100644 --- a/frontend/public/fonts/opensans.css +++ b/frontend/public/css/opensans.css @@ -1,3 +1,12 @@ +html { + font-family: 'Open Sans', 'Arial', sans-serif; +} +@supports (font-variation-settings: normal) { + html { + font-family: 'Open Sans', 'Arial', sans-serif; + } +} + @font-face { font-family: 'Open Sans'; font-style: normal; diff --git a/frontend/public/css/personal.css b/frontend/public/css/personal.css deleted file mode 100644 index 42bebc2..0000000 --- a/frontend/public/css/personal.css +++ /dev/null @@ -1,15 +0,0 @@ -@import url('/fonts/opensans.css'); - -html { - font-family: 'Open Sans', 'Arial', sans-serif; -} -@supports (font-variation-settings: normal) { - html { - font-family: 'Open Sans', 'Arial', sans-serif; - } -} - -html, body { - background: rgb(24, 24, 24); - color: #eee; -} diff --git a/frontend/public/index.html b/frontend/public/index.html index 104eb98..d62487b 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -6,7 +6,7 @@ - + Picsur diff --git a/frontend/src/app.scss b/frontend/src/app.scss index 6d27fd9..ca938d1 100644 --- a/frontend/src/app.scss +++ b/frontend/src/app.scss @@ -1,3 +1,8 @@ +html, body { + background: rgb(24, 24, 24); + color: #eee; +} + html, body, #root { diff --git a/frontend/src/app.tsx b/frontend/src/app.tsx index dad2d1b..ea5995b 100644 --- a/frontend/src/app.tsx +++ b/frontend/src/app.tsx @@ -1,6 +1,5 @@ import { ThemeProvider, createTheme } from '@mui/material/styles'; import CssBaseline from '@mui/material/CssBaseline'; -import Centered from './components/centered/centered'; import './app.scss'; import AppRouter from './routes/router'; import { SnackbarProvider } from 'notistack'; diff --git a/frontend/src/components/header/header.tsx b/frontend/src/components/header/header.tsx index ac1c6c8..dd98773 100644 --- a/frontend/src/components/header/header.tsx +++ b/frontend/src/components/header/header.tsx @@ -1,4 +1,4 @@ -import { AppBar, Toolbar, IconButton, Typography, Button } from '@mui/material'; +import { AppBar, Toolbar, Typography, Button } from '@mui/material'; import { Box } from '@mui/system'; import { Link } from 'react-router-dom'; import './header.scoped.scss'; diff --git a/frontend/src/routes/view/view.tsx b/frontend/src/routes/view/view.tsx index ec9e3f0..6bb011d 100644 --- a/frontend/src/routes/view/view.tsx +++ b/frontend/src/routes/view/view.tsx @@ -1,18 +1,16 @@ import { - Box, Button, Container, Grid, IconButton, TextField, } from '@mui/material'; -import { useEffect, useRef } from 'react'; +import { useEffect } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import ContentCopyIcon from '@mui/icons-material/ContentCopy'; import { useSnackbar } from 'notistack'; import { isHash } from 'class-validator'; import ImagesApi from '../../api/images'; -import Debounce from '../../lib/debounce'; import Centered from '../../components/centered/centered'; import './view.scoped.scss'; diff --git a/shared/src/dto/auth.dto.ts b/shared/src/dto/auth.dto.ts index 4112d82..8d28e4b 100644 --- a/shared/src/dto/auth.dto.ts +++ b/shared/src/dto/auth.dto.ts @@ -50,6 +50,17 @@ export class AuthDeleteRequest { export class AuthDeleteResponse extends EUser {} +export class AuthMeResponse { + @IsDefined() + @ValidateNested() + @Type(() => EUser) + user: EUser; + + @IsString() + @IsDefined() + newJwtToken: string; +} + // Extra export class JwtDataDto { diff --git a/yarn.lock b/yarn.lock index 0201cf2..bfb5307 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5091,27 +5091,6 @@ fastify@3.27.1: semver "^7.3.2" tiny-lru "^7.0.0" -fastify@^3.27.2: - version "3.27.2" - resolved "https://registry.yarnpkg.com/fastify/-/fastify-3.27.2.tgz#61fd226dd72b2d8b6b82e6bf71c18e495026545d" - integrity sha512-InZSbbfdBV8yfsTzX0Ei7aF3r7FjC+DPIf27IlTP5EIhSsvTjvlRNwxDPYYGi2NX2K654Vh+zCGCy/GaSigIuw== - dependencies: - "@fastify/ajv-compiler" "^1.0.0" - abstract-logging "^2.0.0" - avvio "^7.1.2" - fast-json-stringify "^2.5.2" - fastify-error "^0.3.0" - find-my-way "^4.5.0" - flatstr "^1.0.12" - light-my-request "^4.2.0" - pino "^6.13.0" - process-warning "^1.0.0" - proxy-addr "^2.0.7" - rfdc "^1.1.4" - secure-json-parse "^2.0.0" - semver "^7.3.2" - tiny-lru "^8.0.1" - fastq@^1.6.0, fastq@^1.6.1: version "1.13.0" resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.13.0.tgz#616760f88a7526bdfc596b7cab8c18938c36b98c" @@ -9964,11 +9943,6 @@ tiny-lru@^7.0.0: resolved "https://registry.yarnpkg.com/tiny-lru/-/tiny-lru-7.0.6.tgz#b0c3cdede1e5882aa2d1ae21cb2ceccf2a331f24" integrity sha512-zNYO0Kvgn5rXzWpL0y3RS09sMK67eGaQj9805jlK9G6pSadfriTczzLHFXa/xcW4mIRfmlB9HyQ/+SgL0V1uow== -tiny-lru@^8.0.1: - version "8.0.1" - resolved "https://registry.yarnpkg.com/tiny-lru/-/tiny-lru-8.0.1.tgz#c1d77d806e68035aaa2253e253d212291240ece2" - integrity sha512-eBIAYA0BzSjxBedCaO0CSjertD+u+IvNuFkyD7ESf+qjqHKBr5wFqvEYl91+ZQd7jjq2pO6/fBVwFgb6bxvorw== - tmp@^0.0.33: version "0.0.33" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"