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",
|
"bcrypt": "^5.0.1",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.13.2",
|
"class-validator": "^0.13.2",
|
||||||
"fastify": "^3.27.2",
|
|
||||||
"fastify-multipart": "^5.3.1",
|
"fastify-multipart": "^5.3.1",
|
||||||
"fastify-static": "^4.5.0",
|
"fastify-static": "^4.5.0",
|
||||||
"file-type": "^17.1.1",
|
"file-type": "^17.1.1",
|
||||||
@@ -37,11 +36,11 @@
|
|||||||
"passport-jwt": "^4.0.0",
|
"passport-jwt": "^4.0.0",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
"pg": "^8.7.3",
|
"pg": "^8.7.3",
|
||||||
|
"picsur-shared": "*",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rxjs": "^7.5.4",
|
"rxjs": "^7.5.4",
|
||||||
"typeorm": "^0.2.44",
|
"typeorm": "^0.2.44"
|
||||||
"picsur-shared": "*"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nestjs/cli": "^8.2.1",
|
"@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 { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { AuthModule } from './routes/api/auth/auth.module';
|
import { AuthModule } from './routes/api/auth/auth.module';
|
||||||
import { ImageModule } from './routes/image/imageroute.module';
|
import { ImageModule } from './routes/image/imageroute.module';
|
||||||
@@ -29,4 +29,5 @@ import { EImage } from 'picsur-shared/dist/entities/image.entity';
|
|||||||
DemoManagerModule,
|
DemoManagerModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ async function bootstrap() {
|
|||||||
);
|
);
|
||||||
app.useGlobalFilters(new MainExceptionFilter());
|
app.useGlobalFilters(new MainExceptionFilter());
|
||||||
app.useGlobalInterceptors(new SuccessInterceptor());
|
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);
|
await app.listen(Config.main.port, Config.main.host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,12 @@ import { JwtAuthGuard } from './jwt.guard';
|
|||||||
import { AdminGuard } from './admin.guard';
|
import { AdminGuard } from './admin.guard';
|
||||||
import { HasFailed } from 'picsur-shared/dist/types';
|
import { HasFailed } from 'picsur-shared/dist/types';
|
||||||
import AuthFasityRequest from './authrequest';
|
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')
|
@Controller('api/auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
@@ -77,6 +82,10 @@ export class AuthController {
|
|||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get('me')
|
@Get('me')
|
||||||
async me(@Request() req: AuthFasityRequest) {
|
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 { PassportModule } from '@nestjs/passport';
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
import { LocalStrategy } from './local.strategy';
|
import { LocalStrategy } from './local.strategy';
|
||||||
@@ -27,7 +33,6 @@ export class AuthModule implements OnModuleInit {
|
|||||||
|
|
||||||
onModuleInit() {
|
onModuleInit() {
|
||||||
this.checkJwtSecret();
|
this.checkJwtSecret();
|
||||||
|
|
||||||
this.ensureAdminExists();
|
this.ensureAdminExists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { JwtService } from '@nestjs/jwt';
|
import { JwtService } from '@nestjs/jwt';
|
||||||
import * as bcrypt from 'bcrypt';
|
import * as bcrypt from 'bcrypt';
|
||||||
import { plainToClass } from 'class-transformer';
|
import { instanceToPlain, plainToClass } from 'class-transformer';
|
||||||
import { validate } from 'class-validator';
|
import { validate } from 'class-validator';
|
||||||
import { JwtDataDto } from 'picsur-shared/dist/dto/auth.dto';
|
import { JwtDataDto } from 'picsur-shared/dist/dto/auth.dto';
|
||||||
import { EUser } from 'picsur-shared/dist/entities/user.entity';
|
import { EUser } from 'picsur-shared/dist/entities/user.entity';
|
||||||
@@ -51,7 +51,7 @@ export class AuthService {
|
|||||||
throw new Error('Invalid jwt token generated');
|
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> {
|
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-face {
|
||||||
font-family: 'Open Sans';
|
font-family: 'Open Sans';
|
||||||
font-style: normal;
|
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" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
|
||||||
<link rel="stylesheet" href="/css/normalize.css" />
|
<link rel="stylesheet" href="/css/normalize.css" />
|
||||||
<!-- <link rel="stylesheet" href="/css/personal.css" /> -->
|
<link rel="stylesheet" href="/css/opensans.css" />
|
||||||
|
|
||||||
<title>Picsur</title>
|
<title>Picsur</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
html, body {
|
||||||
|
background: rgb(24, 24, 24);
|
||||||
|
color: #eee;
|
||||||
|
}
|
||||||
|
|
||||||
html,
|
html,
|
||||||
body,
|
body,
|
||||||
#root {
|
#root {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
||||||
import CssBaseline from '@mui/material/CssBaseline';
|
import CssBaseline from '@mui/material/CssBaseline';
|
||||||
import Centered from './components/centered/centered';
|
|
||||||
import './app.scss';
|
import './app.scss';
|
||||||
import AppRouter from './routes/router';
|
import AppRouter from './routes/router';
|
||||||
import { SnackbarProvider } from 'notistack';
|
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 { Box } from '@mui/system';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import './header.scoped.scss';
|
import './header.scoped.scss';
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
import {
|
import {
|
||||||
Box,
|
|
||||||
Button,
|
Button,
|
||||||
Container,
|
Container,
|
||||||
Grid,
|
Grid,
|
||||||
IconButton,
|
IconButton,
|
||||||
TextField,
|
TextField,
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
|
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
|
||||||
import { useSnackbar } from 'notistack';
|
import { useSnackbar } from 'notistack';
|
||||||
import { isHash } from 'class-validator';
|
import { isHash } from 'class-validator';
|
||||||
import ImagesApi from '../../api/images';
|
import ImagesApi from '../../api/images';
|
||||||
import Debounce from '../../lib/debounce';
|
|
||||||
import Centered from '../../components/centered/centered';
|
import Centered from '../../components/centered/centered';
|
||||||
|
|
||||||
import './view.scoped.scss';
|
import './view.scoped.scss';
|
||||||
|
|||||||
@@ -50,6 +50,17 @@ export class AuthDeleteRequest {
|
|||||||
|
|
||||||
export class AuthDeleteResponse extends EUser {}
|
export class AuthDeleteResponse extends EUser {}
|
||||||
|
|
||||||
|
export class AuthMeResponse {
|
||||||
|
@IsDefined()
|
||||||
|
@ValidateNested()
|
||||||
|
@Type(() => EUser)
|
||||||
|
user: EUser;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsDefined()
|
||||||
|
newJwtToken: string;
|
||||||
|
}
|
||||||
|
|
||||||
// Extra
|
// Extra
|
||||||
|
|
||||||
export class JwtDataDto {
|
export class JwtDataDto {
|
||||||
|
|||||||
26
yarn.lock
26
yarn.lock
@@ -5091,27 +5091,6 @@ fastify@3.27.1:
|
|||||||
semver "^7.3.2"
|
semver "^7.3.2"
|
||||||
tiny-lru "^7.0.0"
|
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:
|
fastq@^1.6.0, fastq@^1.6.1:
|
||||||
version "1.13.0"
|
version "1.13.0"
|
||||||
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.13.0.tgz#616760f88a7526bdfc596b7cab8c18938c36b98c"
|
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"
|
resolved "https://registry.yarnpkg.com/tiny-lru/-/tiny-lru-7.0.6.tgz#b0c3cdede1e5882aa2d1ae21cb2ceccf2a331f24"
|
||||||
integrity sha512-zNYO0Kvgn5rXzWpL0y3RS09sMK67eGaQj9805jlK9G6pSadfriTczzLHFXa/xcW4mIRfmlB9HyQ/+SgL0V1uow==
|
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:
|
tmp@^0.0.33:
|
||||||
version "0.0.33"
|
version "0.0.33"
|
||||||
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
|
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
|
||||||
|
|||||||
Reference in New Issue
Block a user