Skip to content

Commit 48a0263

Browse files
committed
Fix implicit login/logout on register in & out of sessions
1 parent b26340d commit 48a0263

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/core/authentication/authentication.service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { AuthenticationRepository } from './authentication.repository';
1515
import { CryptoService } from './crypto.service';
1616
import type { LoginInput, RegisterInput, ResetPasswordInput } from './dto';
1717
import { JwtService } from './jwt.service';
18-
import { type Session } from './session/session.dto';
1918
import { SessionHost } from './session/session.host';
2019
import { SessionManager } from './session/session.manager';
2120

@@ -36,10 +35,9 @@ export class AuthenticationService {
3635
private readonly moduleRef: ModuleRef,
3736
) {}
3837

39-
async register(
40-
{ password, ...input }: RegisterInput,
41-
session?: Session,
42-
): Promise<ID> {
38+
async register({ password, ...input }: RegisterInput): Promise<ID> {
39+
const session = this.sessionHost.currentIfInCtx;
40+
4341
// ensure no other tokens are associated with this user
4442
if (session) {
4543
await this.logout(session.token, false);
@@ -64,6 +62,10 @@ export class AuthenticationService {
6462
const passwordHash = await this.crypto.hash(password);
6563
await this.repo.savePasswordHashOnUser(userId, passwordHash);
6664

65+
if (!session) {
66+
return userId;
67+
}
68+
6769
return await this.login({
6870
email: input.email,
6971
password,

0 commit comments

Comments
 (0)