From 5c82bfd532e1bfa79f0762bb3d954b8925d63f35 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 2 May 2023 08:48:23 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=88=E3=83=BC=E3=82=AF=E3=83=B3?= =?UTF-8?q?=E3=80=81=E3=83=AA=E3=83=95=E3=83=AC=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E3=83=88=E3=83=BC=E3=82=AF=E3=83=B3=E3=81=AE=E7=99=BA=E8=A1=8C?= =?UTF-8?q?=E3=81=A8=E3=83=AA=E3=83=95=E3=83=AC=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E3=83=88=E3=83=BC=E3=82=AF=E3=83=B3=E3=81=8B=E3=82=89=E3=83=88?= =?UTF-8?q?=E3=83=BC=E3=82=AF=E3=83=B3=E3=81=AE=E5=86=8D=E7=94=9F=E6=88=90?= =?UTF-8?q?=E3=81=8C=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/dev/usbharu/hideout/Application.kt | 3 ++- .../dev/usbharu/hideout/plugins/Security.kt | 8 +++---- src/main/web/App.tsx | 23 ++++++++++++++----- vite.config.ts | 1 + 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/Application.kt b/src/main/kotlin/dev/usbharu/hideout/Application.kt index 438a49ed..92ec9ee3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/Application.kt +++ b/src/main/kotlin/dev/usbharu/hideout/Application.kt @@ -101,7 +101,8 @@ fun Application.parent() { inject().value, inject().value, inject().value, - inject().value + inject().value, + inject().value ) configureRouting( inject().value, diff --git a/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt b/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt index f2b70cf7..19c3bb60 100644 --- a/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt +++ b/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt @@ -107,14 +107,14 @@ fun Application.configureSecurity( post("/refresh-token") { val refreshToken = call.receive() val findByToken = refreshTokenRepository.findByToken(refreshToken.refreshToken) - ?: return@post call.respond(HttpStatusCode.Forbidden) + ?: return@post call.respondText("token not found",status = HttpStatusCode.Forbidden) if (findByToken.createdAt.isAfter(Instant.now())) { - return@post call.respond(HttpStatusCode.Forbidden) + return@post call.respondText("created_at", status = HttpStatusCode.Forbidden) } - if (findByToken.expiresAt.isAfter(Instant.now())) { - return@post call.respond(HttpStatusCode.Forbidden) + if (findByToken.expiresAt.isBefore(Instant.now())) { + return@post call.respondText( "expires_at", status = HttpStatusCode.Forbidden) } val user = userRepository.findById(findByToken.userId) diff --git a/src/main/web/App.tsx b/src/main/web/App.tsx index 62047d22..0da03fa6 100644 --- a/src/main/web/App.tsx +++ b/src/main/web/App.tsx @@ -18,13 +18,24 @@ export const App: Component = () => { headers: { 'Content-Type': 'application/json' } - }).then(res => res.text()) - .then(res => fetch("/auth-check", { - method: "GET", + }).then(res => res.json()) + // .then(res => fetch("/auth-check", { + // method: "GET", + // headers: { + // 'Authorization': 'Bearer ' + res.token + // } + // })) + // .then(res => res.json()) + .then(res => { + console.log(res.token); + fetch("/refresh-token", { + method: "POST", headers: { - 'Authorization': 'Bearer ' + res - } - })).then(res => console.log(res)) + 'Content-Type': 'application/json', + }, + body: JSON.stringify({refreshToken: res.refreshToken}), + }).then(res=> res.json()).then(res => console.log(res.token)) + }) } }> diff --git a/vite.config.ts b/vite.config.ts index 4ae5194e..3f3c0c58 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -10,6 +10,7 @@ export default defineConfig({ '/api': 'http://localhost:8080', '/login': 'http://localhost:8080', '/auth-check': 'http://localhost:8080', + '/refresh-token': 'http://localhost:8080', } }, root: './src/main/web',