@@ -21,14 +21,14 @@ import {
2121 Throttle ,
2222 URLHelper ,
2323} from '../../base' ;
24+ import { Models , TokenType } from '../../models' ;
2425import { Admin } from '../common' ;
2526import { UserService } from '../user' ;
2627import { UserType } from '../user/types' ;
2728import { validators } from '../utils/validators' ;
2829import { Public } from './guard' ;
2930import { AuthService } from './service' ;
3031import { CurrentUser } from './session' ;
31- import { TokenService , TokenType } from './token' ;
3232
3333@ObjectType ( 'tokenType' )
3434export class ClientTokenType {
@@ -49,7 +49,7 @@ export class AuthResolver {
4949 private readonly url : URLHelper ,
5050 private readonly auth : AuthService ,
5151 private readonly user : UserService ,
52- private readonly token : TokenService
52+ private readonly models : Models
5353 ) { }
5454
5555 @SkipThrottle ( )
@@ -96,7 +96,7 @@ export class AuthResolver {
9696 }
9797
9898 // NOTE: Set & Change password are using the same token type.
99- const valid = await this . token . verifyToken (
99+ const valid = await this . models . verificationToken . verify (
100100 TokenType . ChangePassword ,
101101 token ,
102102 {
@@ -121,9 +121,13 @@ export class AuthResolver {
121121 @Args ( 'email' ) email : string
122122 ) {
123123 // @see [sendChangeEmail]
124- const valid = await this . token . verifyToken ( TokenType . VerifyEmail , token , {
125- credential : user . id ,
126- } ) ;
124+ const valid = await this . models . verificationToken . verify (
125+ TokenType . VerifyEmail ,
126+ token ,
127+ {
128+ credential : user . id ,
129+ }
130+ ) ;
127131
128132 if ( ! valid ) {
129133 throw new InvalidEmailToken ( ) ;
@@ -152,7 +156,7 @@ export class AuthResolver {
152156 throw new EmailVerificationRequired ( ) ;
153157 }
154158
155- const token = await this . token . createToken (
159+ const token = await this . models . verificationToken . create (
156160 TokenType . ChangePassword ,
157161 user . id
158162 ) ;
@@ -195,7 +199,10 @@ export class AuthResolver {
195199 throw new EmailVerificationRequired ( ) ;
196200 }
197201
198- const token = await this . token . createToken ( TokenType . ChangeEmail , user . id ) ;
202+ const token = await this . models . verificationToken . create (
203+ TokenType . ChangeEmail ,
204+ user . id
205+ ) ;
199206
200207 const url = this . url . link ( callbackUrl , { token } ) ;
201208
@@ -215,9 +222,13 @@ export class AuthResolver {
215222 }
216223
217224 validators . assertValidEmail ( email ) ;
218- const valid = await this . token . verifyToken ( TokenType . ChangeEmail , token , {
219- credential : user . id ,
220- } ) ;
225+ const valid = await this . models . verificationToken . verify (
226+ TokenType . ChangeEmail ,
227+ token ,
228+ {
229+ credential : user . id ,
230+ }
231+ ) ;
221232
222233 if ( ! valid ) {
223234 throw new InvalidEmailToken ( ) ;
@@ -233,7 +244,7 @@ export class AuthResolver {
233244 }
234245 }
235246
236- const verifyEmailToken = await this . token . createToken (
247+ const verifyEmailToken = await this . models . verificationToken . create (
237248 TokenType . VerifyEmail ,
238249 user . id
239250 ) ;
@@ -249,7 +260,10 @@ export class AuthResolver {
249260 @CurrentUser ( ) user : CurrentUser ,
250261 @Args ( 'callbackUrl' ) callbackUrl : string
251262 ) {
252- const token = await this . token . createToken ( TokenType . VerifyEmail , user . id ) ;
263+ const token = await this . models . verificationToken . create (
264+ TokenType . VerifyEmail ,
265+ user . id
266+ ) ;
253267
254268 const url = this . url . link ( callbackUrl , { token } ) ;
255269
@@ -266,9 +280,13 @@ export class AuthResolver {
266280 throw new EmailTokenNotFound ( ) ;
267281 }
268282
269- const valid = await this . token . verifyToken ( TokenType . VerifyEmail , token , {
270- credential : user . id ,
271- } ) ;
283+ const valid = await this . models . verificationToken . verify (
284+ TokenType . VerifyEmail ,
285+ token ,
286+ {
287+ credential : user . id ,
288+ }
289+ ) ;
272290
273291 if ( ! valid ) {
274292 throw new InvalidEmailToken ( ) ;
@@ -287,7 +305,7 @@ export class AuthResolver {
287305 @Args ( 'userId' ) userId : string ,
288306 @Args ( 'callbackUrl' ) callbackUrl : string
289307 ) : Promise < string > {
290- const token = await this . token . createToken (
308+ const token = await this . models . verificationToken . create (
291309 TokenType . ChangePassword ,
292310 userId
293311 ) ;
0 commit comments