mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-11-13 23:35:39 +01:00
Add ability to get fresh jwt
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<true> {
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<link rel="stylesheet" href="/css/normalize.css" />
|
||||
<!-- <link rel="stylesheet" href="/css/personal.css" /> -->
|
||||
<link rel="stylesheet" href="/css/opensans.css" />
|
||||
|
||||
<title>Picsur</title>
|
||||
</head>
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
html, body {
|
||||
background: rgb(24, 24, 24);
|
||||
color: #eee;
|
||||
}
|
||||
|
||||
html,
|
||||
body,
|
||||
#root {
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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 {
|
||||
|
||||
26
yarn.lock
26
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"
|
||||
|
||||
Reference in New Issue
Block a user