Skip to content

Commit a774c89

Browse files
committed
Set anonymous agent as the current actor for session instead of faking
1 parent 69f9d60 commit a774c89

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/components/authentication/authentication.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ConfigService, ILogger, Logger } from '../../core';
2121
import { ForgotPassword } from '../../core/email/templates';
2222
import { Privileges, rolesForScope, withoutScope } from '../authorization';
2323
import { AssignableRoles } from '../authorization/dto/assignable-roles';
24+
import { ActorRepository } from '../user/actor.repository';
2425
import { AuthenticationRepository } from './authentication.repository';
2526
import { CryptoService } from './crypto.service';
2627
import { LoginInput, RegisterInput, ResetPasswordInput } from './dto';
@@ -40,6 +41,7 @@ export class AuthenticationService {
4041
@Logger('authentication:service') private readonly logger: ILogger,
4142
private readonly repo: AuthenticationRepository,
4243
private readonly edgedb: EdgeDB,
44+
private readonly actors: ActorRepository,
4345
private readonly moduleRef: ModuleRef,
4446
) {}
4547

@@ -116,7 +118,10 @@ export class AuthenticationService {
116118

117119
const { iat } = this.decodeJWT(token);
118120

119-
const result = await this.repo.resumeSession(token, impersonatee?.id);
121+
const [result, anon] = await Promise.all([
122+
this.repo.resumeSession(token, impersonatee?.id),
123+
this.actors.getAnonymous(),
124+
]);
120125

121126
if (!result) {
122127
this.logger.debug('Failed to find active token in database', { token });
@@ -140,7 +145,7 @@ export class AuthenticationService {
140145
const requesterSession: Session = {
141146
token,
142147
issuedAt: DateTime.fromMillis(iat),
143-
userId: result.userId ?? ('anonuserid' as ID),
148+
userId: result.userId ?? anon.id,
144149
anonymous: !result.userId,
145150
roles: result.roles,
146151
};

0 commit comments

Comments
 (0)