Skip to content

Commit

Permalink
fix(authentication): user id matching on oauth2
Browse files Browse the repository at this point in the history
refactor(database): check for empty queries in sql after $push/$increment ops
  • Loading branch information
kkopanidis committed Apr 28, 2023
1 parent de5851d commit 55ad75e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/authentication/src/handlers/oauth2/OAuth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export abstract class OAuth2<T, S extends OAuth2Settings>
(!payload.hasOwnProperty('email') || isNil(payload.email))
) {
user = await User.getInstance().findOne({
[this.providerName]: { id: payload.id },
[this.providerName + '.id']: payload.id,
});
} else {
throw new GrpcError(
Expand Down
22 changes: 22 additions & 0 deletions modules/database/src/adapters/sequelize-adapter/SequelizeSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ export class SequelizeSchema implements SchemaAdapter<ModelStatic<any>> {
}
delete parsedQuery['$inc'];
}
if (Object.keys(parsedQuery).length === 0) {
return this.model
.findByPk(id, {
nest: true,
include: this.constructAssociationInclusion({}).concat(
this.constructRelationInclusion(populate),
),
})
.then(doc => (doc ? doc.toJSON() : doc));
}

if (parsedQuery.hasOwnProperty('$push')) {
const push = parsedQuery['$push'];
Expand Down Expand Up @@ -192,6 +202,17 @@ export class SequelizeSchema implements SchemaAdapter<ModelStatic<any>> {
delete parsedQuery['$push'];
}

if (Object.keys(parsedQuery).length === 0) {
return this.model
.findByPk(id, {
nest: true,
include: this.constructAssociationInclusion({}).concat(
this.constructRelationInclusion(populate),
),
})
.then(doc => (doc ? doc.toJSON() : doc));
}

parsedQuery.updatedAt = new Date();
incrementDbQueries();
const associationObjects: Indexable = {};
Expand Down Expand Up @@ -411,6 +432,7 @@ export class SequelizeSchema implements SchemaAdapter<ModelStatic<any>> {
const t = await this.sequelize.transaction({ type: Transaction.TYPES.IMMEDIATE });
return this.model
.bulkCreate(parsedQuery, {
validate: true,
include: this.constructAssociationInclusion(assocs, true),
transaction: t,
})
Expand Down

0 comments on commit 55ad75e

Please sign in to comment.