From c5689784e54ccafbcd43466b6742743f62bf70c0 Mon Sep 17 00:00:00 2001 From: Ulung32 <13521122@mahasiswa.itb.ac.id> Date: Fri, 17 Nov 2023 12:56:37 +0700 Subject: [PATCH] register jwt --- src/handler/user/user.service.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/handler/user/user.service.ts b/src/handler/user/user.service.ts index ebbf907..3d5d442 100644 --- a/src/handler/user/user.service.ts +++ b/src/handler/user/user.service.ts @@ -51,11 +51,22 @@ export async function register(user : User) { password : user.password, } }) - responseString = "success"; + const payLoad = { + id: result.id, + name: result.name, + username: result.username, + } + + const Secret = process.env.JWT_SECRET!; + + const expiresIn = 60*60*24; + const token = jwt.sign(payLoad, Secret, {expiresIn: expiresIn}) + return token; }catch (err) { responseString = "failed"; + return responseString; } - return responseString; + } export async function login(username : string, password : string) { -- GitLab