From 0823d28e230642e49553519e7883764637766773 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Tue, 11 Oct 2022 14:44:12 +0200 Subject: [PATCH 1/3] fix: error when refresh token is expired --- frontend/src/services/auth.service.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/frontend/src/services/auth.service.ts b/frontend/src/services/auth.service.ts index 92f8883..f3f6e33 100644 --- a/frontend/src/services/auth.service.ts +++ b/frontend/src/services/auth.service.ts @@ -20,17 +20,20 @@ const signOut = () => { }; const refreshAccessToken = async () => { - const currentAccessToken = getCookie("access_token") as string; + try { + const currentAccessToken = getCookie("access_token") as string; + if ( + currentAccessToken && + (jose.decodeJwt(currentAccessToken).exp ?? 0) * 1000 < + Date.now() + 2 * 60 * 1000 + ) { + const refreshToken = getCookie("refresh_token"); - if ( - currentAccessToken && - (jose.decodeJwt(currentAccessToken).exp ?? 0) * 1000 < - Date.now() + 2 * 60 * 1000 - ) { - const refreshToken = getCookie("refresh_token"); - - const response = await api.post("auth/token", { refreshToken }); - setCookies("access_token", response.data.accessToken); + const response = await api.post("auth/token", { refreshToken }); + setCookies("access_token", response.data.accessToken); + } + } catch { + console.info("Refresh token invalid or expired"); } }; From ffd538f1408733ae3ba36bdd3a57995986fb0fad Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Tue, 11 Oct 2022 15:08:25 +0200 Subject: [PATCH 2/3] fix: delete files when deleting share manually --- backend/src/share/share.module.ts | 7 +++---- backend/src/share/share.service.ts | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/src/share/share.module.ts b/backend/src/share/share.module.ts index a5f4b1f..f7a5fef 100644 --- a/backend/src/share/share.module.ts +++ b/backend/src/share/share.module.ts @@ -1,12 +1,11 @@ -import { Module } from "@nestjs/common"; -import { JwtModule, JwtService } from "@nestjs/jwt"; -import { AuthModule } from "src/auth/auth.module"; +import { forwardRef, Module } from "@nestjs/common"; +import { JwtModule } from "@nestjs/jwt"; import { FileModule } from "src/file/file.module"; import { ShareController } from "./share.controller"; import { ShareService } from "./share.service"; @Module({ - imports: [JwtModule.register({})], + imports: [JwtModule.register({}), forwardRef(() => FileModule)], controllers: [ShareController], providers: [ShareService], exports: [ShareService], diff --git a/backend/src/share/share.service.ts b/backend/src/share/share.service.ts index a6fa6fc..d15dc52 100644 --- a/backend/src/share/share.service.ts +++ b/backend/src/share/share.service.ts @@ -11,6 +11,7 @@ import * as archiver from "archiver"; import * as argon from "argon2"; import * as fs from "fs"; import * as moment from "moment"; +import { FileService } from "src/file/file.service"; import { PrismaService } from "src/prisma/prisma.service"; import { CreateShareDTO } from "./dto/createShare.dto"; @@ -18,7 +19,7 @@ import { CreateShareDTO } from "./dto/createShare.dto"; export class ShareService { constructor( private prisma: PrismaService, - + private fileService: FileService, private config: ConfigService, private jwtService: JwtService ) {} @@ -139,6 +140,7 @@ export class ShareService { if (!share) throw new NotFoundException("Share not found"); + await this.fileService.deleteAllFiles(shareId); await this.prisma.share.delete({ where: { id: shareId } }); } From e2b3e6a1e86af95e1d9d20e7dd179c1a0ee6109f Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Tue, 11 Oct 2022 15:14:29 +0200 Subject: [PATCH 3/3] fix: add error handling for uploading --- frontend/src/pages/upload.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/upload.tsx b/frontend/src/pages/upload.tsx index 1fcc72c..2af653d 100644 --- a/frontend/src/pages/upload.tsx +++ b/frontend/src/pages/upload.tsx @@ -1,5 +1,6 @@ import { Button, Group } from "@mantine/core"; import { useModals } from "@mantine/modals"; +import axios from "axios"; import { useRouter } from "next/router"; import { useState } from "react"; import Meta from "../components/Meta"; @@ -11,6 +12,7 @@ import useUser from "../hooks/user.hook"; import shareService from "../services/share.service"; import { FileUpload } from "../types/File.type"; import { ShareSecurity } from "../types/share.type"; +import toast from "../utils/toast.util"; const Upload = () => { const router = useRouter(); @@ -49,10 +51,15 @@ const Upload = () => { setFiles([]); } } - } catch { + } catch (e) { files.forEach((file) => { file.uploadingState = undefined; }); + if (axios.isAxiosError(e)) { + toast.error(e.response?.data?.message ?? "An unkown error occured."); + } else { + toast.error("An unkown error occured."); + } setFiles([...files]); setisUploading(false); }