Skip to content

Commit 2f23665

Browse files
author
hersveit
committed
sign out
1 parent 6917e0c commit 2f23665

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

apps/api/src/modules/auth/auth.service.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import { v4 } from 'uuid';
88
import { ConfigModel } from '../../config/config.model';
99
import { UserService } from '../user/user.service';
1010
import { 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';
1217
import { 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

Comments
 (0)