Skip to content

Commit

Permalink
Merge pull request #127 from finkinfridom/feature/test-merges
Browse files Browse the repository at this point in the history
feat: updated strategy
  • Loading branch information
finkinfridom authored Mar 15, 2023
2 parents d8c5a13 + dbce910 commit 1274d77
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TYPESCRIPT_ES_CONFIG_FILE: .eslintrc.json
TYPESCRIPT_DEFAULT_STYLE: prettier
VALIDATE_GITLEAKS: false
USE_FIND_ALGORITHM: true
LINTER_RULES_PATH: /
6 changes: 3 additions & 3 deletions __tests__/Auth0Strategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ describe("Auth0Strategy", () => {
expect(strategy.name).toBe("auth0");
});
describe("authenticate", () => {
it("should fallback to standard user-pwd login", () => {
it("should fallback to standard user-pwd login", async () => {
const req = {
user: {
id: "test",
},
} as unknown as Request;
strategy.authenticate(req);
await strategy.authenticate(req);
expect(strategy.success).toBeCalledWith(req.user);
});
it("invalid 'oidc' should return error", async () => {
Expand Down Expand Up @@ -70,7 +70,7 @@ describe("Auth0Strategy", () => {
.spyOn(strategy.ctx, "find")
.mockResolvedValue({ docs: [] } as unknown as PaginatedDocs<any>);
await strategy.authenticate(req);
expect(spyFind).toBeCalledTimes(1);
expect(spyFind).toBeCalledTimes(2);
expect(spyCreate).toBeCalledTimes(1);
expect(protoSuccessMock).toBeCalledWith({
id: "non-existing-oidc",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "payload-auth0-plugin",
"version": "0.0.10",
"version": "0.1.0",
"main": "dist/strategies/index.js",
"types": "dist/strategies/index.d.ts",
"repository": "https://github.com/finkinfridom/payload-auth0-plugin.git",
Expand Down
15 changes: 13 additions & 2 deletions src/strategies/Auth0Strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,26 @@ export class Auth0Strategy extends Strategy {
},
});
}
findUser(oidcUser): Promise<PaginatedDocs<any>> {
return this.ctx.find({
async findUser(oidcUser): Promise<PaginatedDocs<any>> {
const result = await this.ctx.find({
collection: this.slug,
where: {
sub: {
equals: oidcUser.sub,
},
},
});
if (result.docs && result.docs.length) {
return Promise.resolve(result);
}
return this.ctx.find({
collection: this.slug,
where: {
email: {
equals: oidcUser.email,
},
},
});
}

async mergeUsers(foundUser, oidcUser): Promise<void> {
Expand Down

0 comments on commit 1274d77

Please sign in to comment.