@@ -8,7 +8,7 @@ import { verify as argon2Verify } from 'argon2';
88import { Agents } from '~/core/agents/_schemas/agents.schema' ;
99import { AgentsService } from '~/core/agents/agents.service' ;
1010import { AgentType } from '~/_common/types/agent.type' ;
11- import { omit } from 'radash' ;
11+ import { omit , pascal , pick } from 'radash' ;
1212import { JwtPayload } from 'jsonwebtoken' ;
1313import { JwtService } from '@nestjs/jwt' ;
1414import { resolve } from 'path' ;
@@ -81,6 +81,7 @@ export class AuthService extends AbstractService implements OnModuleInit {
8181
8282 // eslint-disable-next-line
8383 public async verifyIdentity ( payload : any & { identity : AgentType & { token : string } } ) : Promise < any > {
84+ console . log ( 'payload' , payload ) ;
8485 if ( payload . scopes . includes ( 'offline' ) ) {
8586 return payload . identity ;
8687 }
@@ -100,6 +101,7 @@ export class AuthService extends AbstractService implements OnModuleInit {
100101 const identity = await this . redis . get ( [ this . ACCESS_TOKEN_PREFIX , payload . jti ] . join ( ':' ) ) ;
101102 if ( identity ) {
102103 const data = JSON . parse ( identity ) ;
104+ console . log ( 'data' , data ) ;
103105 const success = await this . agentsService . model . countDocuments ( {
104106 _id : payload . identity . _id ,
105107 'security.secretKey' : data . identity ?. security ?. secretKey ,
@@ -125,7 +127,7 @@ export class AuthService extends AbstractService implements OnModuleInit {
125127 if ( options ?. scopes ) scopes . push ( ...options . scopes ) ;
126128 const jwtid = `${ identity . _id } _${ randomBytes ( 16 ) . toString ( 'hex' ) } ` ;
127129 const access_token = this . jwtService . sign (
128- { identity, scopes } ,
130+ { identity : pick ( identity , [ '_id' , 'username' , 'email' ] ) , scopes } ,
129131 {
130132 expiresIn : this . ACCESS_TOKEN_EXPIRES_IN ,
131133 jwtid,
@@ -147,10 +149,11 @@ export class AuthService extends AbstractService implements OnModuleInit {
147149 [ this . REFRESH_TOKEN_PREFIX , refresh_token ] . join ( this . TOKEN_PATH_SEPARATOR ) ,
148150 this . REFRESH_TOKEN_EXPIRES_IN ,
149151 ) ;
152+ const userIdentity = await this . agentsService . findOne < Agents > ( { _id : identity . _id } ) ;
150153 await this . redis . set (
151154 [ this . ACCESS_TOKEN_PREFIX , jwtid ] . join ( this . TOKEN_PATH_SEPARATOR ) ,
152155 JSON . stringify ( {
153- identity,
156+ identity : userIdentity . toJSON ( ) ,
154157 refresh_token,
155158 } ) ,
156159 'EX' ,
@@ -162,19 +165,18 @@ export class AuthService extends AbstractService implements OnModuleInit {
162165 } ;
163166 }
164167
165- //TODO: change any
166168 public async getSessionData ( identity : AgentType ) : Promise < AgentType > {
167- // const entity = await this.agentsService.findOne<Agents>(
168- // { _id: identity.entityId },
169- // {
170- // projection: {
171- // metadata: 0,
172- // },
173- // },
174- // )
169+ const entity = await this . agentsService . findOne < Agents > (
170+ { _id : identity . _id } ,
171+ {
172+ projection : {
173+ metadata : 0 ,
174+ password : 0 ,
175+ } ,
176+ } ,
177+ )
175178 return {
176- ...identity ,
177- // entity,
179+ ...omit ( entity . toJSON ( ) , [ 'password' ] ) ,
178180 } ;
179181 }
180182
0 commit comments