@@ -8,7 +8,12 @@ import { v4 } from 'uuid';
88import { ConfigModel } from '../../config/config.model' ;
99import { UserService } from '../user/user.service' ;
1010import { SignInBody , SignUpBody } from './common/auth.dto' ;
11- import { CannotFindEmailConfirm , EmailAlreadyConfirmed , EmailNotConfirmed } from './common/auth.errors' ;
11+ import {
12+ CannotFindEmailConfirm ,
13+ EmailAlreadyConfirmed ,
14+ EmailNotConfirmed ,
15+ EmailOrPasswordIncorrect ,
16+ } from './common/auth.errors' ;
1217import { GetTokenResult } from './common/auth.model' ;
1318
1419@Injectable ( )
@@ -32,12 +37,12 @@ export class AuthService {
3237 }
3338 }
3439
35- async signIn ( body : SignInBody ) : Promise < GetTokenResult | UserNotFound | EmailNotConfirmed > {
40+ async signIn ( body : SignInBody ) : Promise < GetTokenResult | EmailOrPasswordIncorrect | EmailNotConfirmed > {
3641 const hash = SHA256 ( body . password ) . toString ( ) ;
3742 const user = await this . rep . user . findOne ( { where : { email : body . email , hash } } ) ;
3843
3944 if ( ! user ) {
40- return new UserNotFound ( { email : body . email } ) ;
45+ return new EmailOrPasswordIncorrect ( body . email ) ;
4146 }
4247
4348 if ( ! user . emailConfirmed ) {
@@ -54,6 +59,14 @@ export class AuthService {
5459 } ;
5560 }
5661
62+ async signOut ( email : string ) {
63+ const user = await this . rep . user . findOne ( { where : { email } } ) ;
64+ if ( user ) {
65+ user . refreshTokenHash = undefined ;
66+ await this . rep . user . save ( user ) ;
67+ }
68+ }
69+
5770 async refresh ( id : number ) : Promise < GetTokenResult | UserNotFound > {
5871 const user = await this . rep . user . findOne ( { where : { id } } ) ;
5972 if ( ! user ) {
0 commit comments