refactor source code
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { Global, Module } from '@nestjs/common'
|
||||
|
||||
import { CommonGraphqlError } from './graphql/common.graphql.error';
|
||||
import { JwtUtils } from './utils/jwt.utils';
|
||||
import { CommonGraphqlError } from './graphql/common.graphql.error'
|
||||
import { JwtUtils } from './utils/jwt.utils'
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [],
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Builder } from '../../Graphql/graphql.builder';
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import { Builder } from '../../Graphql/graphql.builder'
|
||||
import {
|
||||
PothosRef,
|
||||
PothosSchema,
|
||||
SchemaBuilderToken,
|
||||
} from '@smatch-corp/nestjs-pothos';
|
||||
} from '@smatch-corp/nestjs-pothos'
|
||||
|
||||
@Injectable()
|
||||
export class CommonGraphqlError extends PothosSchema {
|
||||
constructor(@Inject(SchemaBuilderToken) private readonly builder: Builder) {
|
||||
super();
|
||||
super()
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
@@ -19,6 +19,6 @@ export class CommonGraphqlError extends PothosSchema {
|
||||
fields: (t) => ({
|
||||
message: t.exposeString('message'),
|
||||
}),
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import { sign, verify } from 'jsonwebtoken';
|
||||
import { sign, verify } from 'jsonwebtoken'
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class JwtUtils {
|
||||
signToken(payload: string, expiresIn: string) {
|
||||
return sign(payload, process.env.JWT_SECRET!, { expiresIn });
|
||||
return sign(payload, process.env.JWT_SECRET!, { expiresIn })
|
||||
}
|
||||
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
signTokenRS256(payload: any, expiresIn: string) {
|
||||
const privateKey = process.env.JWT_RS256_PRIVATE_KEY!;
|
||||
const privateKey = process.env.JWT_RS256_PRIVATE_KEY!
|
||||
return sign(payload, privateKey, {
|
||||
algorithm: 'RS256',
|
||||
expiresIn,
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
verifyTokenRS256(token: string) {
|
||||
const publicKey = process.env.JWT_RS256_PUBLIC_KEY!;
|
||||
const publicKey = process.env.JWT_RS256_PUBLIC_KEY!
|
||||
return verify(token, publicKey, {
|
||||
algorithms: ['RS256'],
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
verifyToken(token: string) {
|
||||
return verify(token, process.env.JWT_SECRET!);
|
||||
return verify(token, process.env.JWT_SECRET!)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user