feat(services): update JWT methods in jwt.service.ts
Update the methods related to JWT in `jwt.service.ts`. Import and utilize `jwtVerify` and `SignJWT` from the "jose" package, replacing their previous counterparts. This refactors the `JwtVerifyService` and `JwtSignService` functions for better JWT handling. Issue: #30 Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
parent
3231f916f8
commit
0887fe213f
@ -1,4 +1,4 @@
|
|||||||
import Jose, {type JWTHeaderParameters, type JWTPayload} from "jose";
|
import {type JWTHeaderParameters, type JWTPayload, jwtVerify, SignJWT} from "jose";
|
||||||
import {Logger} from "tslog";
|
import {Logger} from "tslog";
|
||||||
|
|
||||||
const logger = new Logger({ name: "JwtService" });
|
const logger = new Logger({ name: "JwtService" });
|
||||||
@ -13,7 +13,7 @@ const logger = new Logger({ name: "JwtService" });
|
|||||||
*/
|
*/
|
||||||
async function JwtVerifyService(jwt: string | Uint8Array): Promise<null | JWTPayload> {
|
async function JwtVerifyService(jwt: string | Uint8Array): Promise<null | JWTPayload> {
|
||||||
try {
|
try {
|
||||||
const result = await Jose.jwtVerify(
|
const result = await jwtVerify(
|
||||||
jwt,
|
jwt,
|
||||||
new TextEncoder()
|
new TextEncoder()
|
||||||
.encode(`${process.env["JWT_SECRET"]}`),
|
.encode(`${process.env["JWT_SECRET"]}`),
|
||||||
@ -43,7 +43,7 @@ async function JwtVerifyService(jwt: string | Uint8Array): Promise<null | JWTPay
|
|||||||
* - A promise that resolves with the signed JWT token.
|
* - A promise that resolves with the signed JWT token.
|
||||||
*/
|
*/
|
||||||
async function JwtSignService(payload: JWTPayload, pHeader: JWTHeaderParameters, expTime: string | number | Date, audience: string | string[]): Promise<string> {
|
async function JwtSignService(payload: JWTPayload, pHeader: JWTHeaderParameters, expTime: string | number | Date, audience: string | string[]): Promise<string> {
|
||||||
return await new Jose.SignJWT(payload)
|
return await new SignJWT(payload)
|
||||||
.setProtectedHeader(pHeader)
|
.setProtectedHeader(pHeader)
|
||||||
.setIssuedAt(new Date())
|
.setIssuedAt(new Date())
|
||||||
.setIssuer(`${process.env["JWT_SECRET"]} - Mathis HERRIOT`)
|
.setIssuer(`${process.env["JWT_SECRET"]} - Mathis HERRIOT`)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user