Skip to content

Commit 66d32b6

Browse files
committed
Fix impersonator to use ALS
1 parent f162850 commit 66d32b6

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/components/authentication/authentication.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,11 @@ export class AuthenticationService {
231231
}
232232

233233
async asUser<R>(
234-
userId: ID<'User'>,
234+
user: ID<'User'> | Session,
235235
fn: (session: Session) => Promise<R>,
236236
): Promise<R> {
237-
const session = await this.sessionForUser(userId);
237+
const session =
238+
typeof user === 'string' ? await this.sessionForUser(user) : user;
238239
return await this.sessionHost.withSession(session, () => fn(session));
239240
}
240241

src/components/authentication/session.resolver.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ export class SessionResolver {
115115
async impersonator(
116116
@Parent() { session }: SessionOutput,
117117
): Promise<User | null> {
118-
if (session.anonymous || !session.impersonator) {
118+
const { impersonator } = session;
119+
if (session.anonymous || !impersonator) {
119120
return null;
120121
}
121122
// Edge case: Load the impersonator, as the impersonator, rather than the impersonatee.
122123
// They should still be able to see their own props from this field.
123124
// Otherwise, it could be that the impersonatee can't see the impersonator's roles,
124125
// and now the UI can't stop impersonating because it doesn't know the impersonator's roles.
125-
return await this.users.readOne(
126-
session.impersonator.userId,
127-
session.impersonator, // instead of `session`
126+
return await this.authentication.asUser(impersonator, (_) =>
127+
this.users.readOne(impersonator.userId, _),
128128
);
129129
}
130130

0 commit comments

Comments
 (0)