Skip to content

Commit aed8ad4

Browse files
author
hersveit
committed
fix sign-out; sign-out controller
1 parent 7bbac67 commit aed8ad4

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
signInToCookie,
1414
} from './common/auth.model';
1515
import { JwtUserRefreshGuard } from './guards/jwt-user-refresh.guard';
16+
import { JwtUserGuard } from './guards/jwt-user.guard';
1617

1718
@Controller('/api/auth')
1819
export class AuthController {
@@ -32,6 +33,14 @@ export class AuthController {
3233
return makeResponse(await this.authService.signIn(body), signInToBody, signInToCookie);
3334
}
3435

36+
@Post('/sign-out')
37+
@UseValidationPipe()
38+
@UseGuards(JwtUserGuard)
39+
@Transactional()
40+
async signOut(@User() user: ContextUser) {
41+
return makeResponse(await this.authService.signOut(user.id), identity);
42+
}
43+
3544
@Post('/confirm-email')
3645
@UseValidationPipe()
3746
@Transactional()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ export class AuthService {
5959
};
6060
}
6161

62-
async signOut(email: string) {
63-
const user = await this.rep.user.findOne({ where: { email } });
62+
async signOut(id: number) {
63+
const user = await this.rep.user.findOne({ where: { id } });
6464
if (user) {
65-
user.refreshTokenHash = undefined;
65+
user.refreshTokenHash = null;
6666
await this.rep.user.save(user);
6767
}
6868
}

libs/repository/src/entities/user.entity.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export class UserEntity {
1717
@Column({ default: false })
1818
emailConfirmed: boolean;
1919

20-
@Column({ nullable: true })
21-
refreshTokenHash?: string;
20+
@Column({ type: 'text', nullable: true })
21+
refreshTokenHash?: string | null;
2222

23-
@Column({ nullable: true })
24-
emailConfirmToken?: string;
23+
@Column({ type: 'text', nullable: true })
24+
emailConfirmToken?: string | null;
2525
}

0 commit comments

Comments
 (0)