@@ -7,17 +7,12 @@ import type {
77 JWTEmployeeAccessTokenPayload ,
88 JWTEmployeeData ,
99} from '@api-sdk' ;
10- import { PrismaService } from '@/db/prisma.service' ;
11- import { EmployeeService } from '@/core/employee/employee.service' ;
12- import { SignInByEmailDto } from '@/core/auth/dto/signin-by-email.dto' ;
1310
1411@Injectable ( )
1512export class AuthService {
1613 constructor (
1714 private readonly config : ConfigService ,
18- private readonly employee : EmployeeService ,
1915 private readonly jwt : JwtService ,
20- private readonly prisma : PrismaService ,
2116 ) { }
2217
2318 async verifyToken ( token : string ) {
@@ -38,32 +33,13 @@ export class AuthService {
3833 }
3934 }
4035
41- async signInByEmail ( dto : SignInByEmailDto ) {
42- const employee = await this . employee . findEmployeeByContact (
43- dto . email ,
44- 'EMAIL' ,
45- ) ;
46- if ( ! employee ) {
47- return null ;
48- }
49-
50- const isPasswordValid = await this . employee . checkPassword (
51- employee . id ,
52- dto . password ,
53- ) ;
54- if ( ! isPasswordValid ) {
55- return null ;
56- }
57-
58- // Get all Permissions
59- const permissions = employee . permissions . map (
60- ( p : { type : EmployeePermissionType } ) => p . type ,
61- ) ;
62-
63- // Generate a JWT
36+ async createToken (
37+ userId : string ,
38+ permissions : EmployeePermissionType [ ] ,
39+ ) : Promise < string > {
6440 const sub = createId ( ) ;
6541 const user : JWTEmployeeData = {
66- id : employee . id ,
42+ id : userId ,
6743 permissions,
6844 } ;
6945
@@ -72,15 +48,8 @@ export class AuthService {
7248 user,
7349 } ;
7450
75- const access_token = await this . jwt . signAsync ( payload , {
51+ return this . jwt . signAsync ( payload , {
7652 secret : this . config . getOrThrow ( 'JWT_SECRET' ) ,
7753 } ) ;
78-
79- return {
80- ok : true ,
81- result : {
82- access_token,
83- } ,
84- } ;
8554 }
8655}
0 commit comments