Skip to content

Commit

Permalink
fix scope
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed May 23, 2024
1 parent 3c6d028 commit 7420c91
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/server/backend/$base/server/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export abstract class UserProvider<Id, ScoreId> extends IdTransformable {
hashedPassword: string,
): Promise<[boolean, UserCompact<Id> | undefined]>

abstract getCompactById(id: Id /** , opt?: { scope: Scope } */): Promise<UserCompact<Id>>
abstract getCompactById(id: Id): Promise<UserCompact<Id>>

abstract getByEmail(email: MailTokenProvider.Email, opt?: { scope: Scope }): Promise<UserCompact<Id>>

Expand Down
6 changes: 3 additions & 3 deletions src/server/backend/bancho.py/server/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class DBUserProvider extends Base<Id, ScoreId> implements Base<Id, ScoreId> {
return !!res
}

async getCompactById(id: Id, _opt?: { scope: Scope }) {
async getCompactById(id: Id) {
const user = await this.drizzle.query.users.findFirst({
where: eq(schema.users.id, id),
columns: userCompactFields,
Expand All @@ -148,11 +148,11 @@ class DBUserProvider extends Base<Id, ScoreId> implements Base<Id, ScoreId> {
return toUserCompact(user, this.config)
}

async getByEmail(email: MailTokenProvider.Email, opt?: { scope: Scope }): Promise<UserCompact<number>> {
async getByEmail(email: MailTokenProvider.Email, opt: { scope: Scope }): Promise<UserCompact<number>> {
return this.getCompact({ handle: email, scope: opt?.scope, keys: ['email'] })
}

async getCompact(opt: Base.OptType & { scope?: Scope }) {
async getCompact(opt: Base.OptType & { scope: Scope }) {
const { handle, scope, keys = ['id', 'name', 'safeName', 'email'] } = opt

let handleNum = +handle
Expand Down
2 changes: 1 addition & 1 deletion src/server/trpc/routers/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export const router = _router({
)
.query(async ({ input: { target }, ctx }) => {
const fromUser = ctx.user
const targetUser = await users.getCompact({ handle: target })
const targetUser = await users.getCompact({ handle: target, scope: Scope.Self })

if (!fromUser || targetUser == null) {
return
Expand Down
4 changes: 2 additions & 2 deletions src/server/trpc/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const router = _router({
}),
)
.query(async ({ input }) => {
const user = await users.getCompact({ handle: input.handle })
const user = await users.getCompact({ handle: input.handle, scope: Scope.Public })

return mapId(user, UserProvider.idToString)
}),
Expand Down Expand Up @@ -294,7 +294,7 @@ export const router = _router({
.mutation(async ({ ctx, input }) => {
const variant = Mail.Variant.AccountRecovery

const user = await users.getByEmail(input as MailTokenProvider.Email)
const user = await users.getByEmail(input as MailTokenProvider.Email, { scope: Scope.Self })

const { otp, token } = await mailToken.getOrCreate(input as MailTokenProvider.Email)
const t = await useTranslation(ctx.h3Event)
Expand Down

0 comments on commit 7420c91

Please sign in to comment.